Skip to content

Instantly share code, notes, and snippets.

@JohnsonLuu
Created June 24, 2020 03:33
Show Gist options
  • Save JohnsonLuu/4bd4490587cf4889290d984c912580aa to your computer and use it in GitHub Desktop.
Save JohnsonLuu/4bd4490587cf4889290d984c912580aa to your computer and use it in GitHub Desktop.
DNA Sequencing - Java - Code Academy
// This program recieves a given string in DNA and checks if any proteins are within.
// Does not consider that multiple proteins could be present.
// -. .-. .-. .-. .
// \ \ / \ \ /
// / \ \ / \ \
// ~ `-~ `-` `-~ `-
public class DNA {
public static void main(String[] args) {
String dna1 = "ATGCGATACGCTTGA";
String dna2 = "ATGCGATACGTGA";
String dna3 = "ATTAATATGTACTGA";
// Change the value of DNA to check other strings
String dna = dna1;
int start = dna.indexOf("ATG");
int stop = dna.indexOf("TGA");
System.out.println(start + " " + stop);
if (start != -1 && stop != -1 && (stop - start) % 3 == 0) {
String protein = dna.substring(start, stop+3);
System.out.println("Protein: " + protein);
} else {
System.out.println("No protein.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment