Skip to content

Instantly share code, notes, and snippets.

@bonicim
Created January 10, 2023 18:21
Show Gist options
  • Save bonicim/a6ae5e395cc1f1bb0eb566c9915a49a0 to your computer and use it in GitHub Desktop.
Save bonicim/a6ae5e395cc1f1bb0eb566c9915a49a0 to your computer and use it in GitHub Desktop.
Lab - DNA Sequencing
public class DNA {
public static void main(String[] args) {
// DNA strand
// protein:
// start codon: ATG
// stop codon: TGA
// sequence of three nucelotides
// divisible by 3
// determines if DNA strand is a protein
String dna1 = "ATGCGATACGCTTGA";
String dna2 = "ATGCGATACGTGA";
String dna3 = "ATTAATATGTACTGA";
String dna = dna3;
// Task 0: Write a comment that describes what this program does
// Task 0.1: Write tests
// Task 1: Print length of dna
// Task 2: Print the index of the start codon in dna
// find index of the start codon
// Task 3: Print the index of the stop codon
// Task 4: Find the protein
// Task 5: Check for number of nucleotides inside protein is multiple of 3
// Task 6: Get the nucleotide if multiple of 3
// Task 7: Create a method call printProtein
String startCodon = "ATG";
String stopCodon = "TGA";
int start = dna.indexOf(startCodon);
int stop = dna.indexOf(stopCodon);
if (start != -1 && stop != 1 && ((stop - start) % 3 == 0)) {
System.out.println("We have a protein");
String protein = dna.substring(start, stop + 3);
System.out.println(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