Skip to content

Instantly share code, notes, and snippets.

@nherbaut
Created October 5, 2023 12:33
Show Gist options
  • Save nherbaut/6cd05a4b9adad19f2a2efc512a64e592 to your computer and use it in GitHub Desktop.
Save nherbaut/6cd05a4b9adad19f2a2efc512a64e592 to your computer and use it in GitHub Desktop.
L2.3.7 Algorithme final de recherche de gène

codez public String getFirstGene() et private int findStopCodon(int startIndex, String stopCodon)

public class DNA {
public final String strand;
public DNA(String strand) {
this.strand = strand;
}
public String getFirstGene() {
// trouver la première occurrence d'ATG et l'appeller startIndex
// si startIndex = -1 retourne la chaîne vide.
// findStopCodon(dnaStr,startIndex,"TAA") et appeler le résultat taaIndex
// findStopCodon(dnaStr,startIndex,"TAG") et appeler le résultat tagIndex
// findStopCodon(dnaStr,startIndex,"TGA") et appeler le résultat tgaIndex
// prendre le plus petit entre taaIndex, tagIndex, tgaIndex et l'appeller minIndex
// si minIndex=dnaStr alors la réponse est une chaine vide $
// La réponse est le texte commençant à startIndex jusqu'à minIndex + 3
return "";
}
private int findStopCodon(int startIndex, String stopCodon) {
// trouver le **stopCodon** commençant après l'index $(\text{startIndex} + 3)$, appeler ce résultat $\text{currIndex}$
// Tant que **$currIndex \neq -1$**
// Vérifier que $(\text{currIndex}-\text{startIndex})$ est un multiple de $3$
// Si VRAI, $\text{currIndex}$ est la réponse
// Si FAUX, mettre à jour *currIndex* à l'index du prochain **stopCodon**), en commençant à $(\text{currIndex} + 1)$
// retourner dnaStr.lenghth()
return 0;
}
public static void main(String[] args) {
DNA dna1 = new DNA("xxxxxxxxxxxxATGyyyzzzTAAiiiiiiii");
System.out.println("DNA1:" + dna1.getFirstGene());
/// DNA1:ATGyyyzzzTAA
DNA dna2 = new DNA("xxxxxxxxxxxxATGyyyzzTAAiiiiTAGiiiiii");
System.out.println("DNA2: " + dna2.getFirstGene());
//DNA2: ATGyyyzzTAAiiiiTAG
DNA dna3 = new DNA("xxxxxxxxATGxxTAATGAATGA");
System.out.println("DNA3:" + dna3.getFirstGene());
//DNA3: ATGxxTAATGAATGA
DNA dna4 = new DNA("xxxxxxxxxxxATGyyyyyyyyy");
System.out.println("DNA4:" + dna4.getFirstGene());
//DNA4:
DNA dna5 = new DNA("xxxxxxxxxxATGxxxxxxxxTGAcccc");
System.out.println("DNA5:" + dna5.getFirstGene());
//DNA5:d
}
}
@nherbaut
Copy link
Author

nherbaut commented Oct 5, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment