DNA class- bioinformatics(
I have made a class named DNA performing several functions on a DNA sequence. I am not satisfied with my code. Can you guys run it and tell me how to improve it?
The major pitfalls which i can see are:
- Method readingFrames() and ORF():
The readingFrames() method invokes the ORF() method and it needs to pass in six different reading frames of the DNA sequence to the ORF(). For that the reading frame has to store all six reading frames of the DNA sequence in six different strings.
so it has that many statements. Would that it wouldnt need to store the six reading reading frames in six different strings and them then pass in to the ORF(), it could easily have done the job in a single for loop, containing two statements- one printing a reading frame and the other printing the reverse of the first reading frame( giving the 2nd reading frame).
Then in the ORF(), i have separately check for each reading frame if it is an open reading frame. For that i have to pass each of the six string to a another method which returns codons(triplets) made from the sequence.
Can't I do that in a loop? Can't i just achieve the passing in of a different string to the invoked method in each iteration of a loop?
Because this long code makes my code less efficient. :(
Code:
void readingFrames(){
String s1, s2, s3, s4, s5, s6;
System.out.println("\nReading Frame 1:" + seq.substring(0,seq.length()-1));
s1=seq.substring(0,seq.length()-1);
System.out.println("\nReading Frame -1:" + new StringBuilder( seq.substring(1,seq.length()-1)).reverse().toString());
s2= new StringBuilder( seq.substring(1,seq.length()-1)).reverse().toString();
System.out.println("\nReading Frame 2:" + seq.substring(0,seq.length()-1));
s3=seq.substring(0,seq.length()-1);
System.out.println("\nReading Frame -2:" + new StringBuilder( seq.substring(1,seq.length()-1)).reverse().toString());
s4= new StringBuilder( seq.substring(1,seq.length()-1)).reverse().toString();
System.out.println("\nReading Frame 3:" + seq.substring(0,seq.length()-1));
s5=seq.substring(0,seq.length()-1);
System.out.println("\nReading Frame -3:" + new StringBuilder( seq.substring(1,seq.length()-1)).reverse().toString());
s6= new StringBuilder( seq.substring(1,seq.length()-1)).reverse().toString();
System.out.println("\n\nLET's SEE IF AN OPEN READING FRAME IS PRESENT IN THESE READING FRAMES:\n");
ORF(s1,s2,s3,s4,s5,s6);
}
void ORF(String s1,String s2,String s3,String s4,String s5,String s6){
String[] make_codons= makeCodons(s1);
ArrayList al= new ArrayList();
for (int ix=0; ix<make_codons.length; ix++) {
al.add(make_codons[ix]);
}if(al.contains("tag")||al.contains("tga")||al.contains("taa")){ }
else{
System.out.println("An ORF found :)\n" + s1);
}
make_codons= makeCodons(s2);
for (int ix=0; ix<make_codons.length; ix++) {
al.add(make_codons[ix]);
}if(al.contains("tag")||al.contains("tga")||al.contains("taa")){ }
else{
System.out.println("An ORF found :)\n" + s2);
}
make_codons= makeCodons(s3);
for (int ix=0; ix<make_codons.length; ix++) {
al.add(make_codons[ix]);
}if(al.contains("tag")||al.contains("tga")||al.contains("taa")){ }
else{
System.out.println("An ORF found :)\n" + s3);
}
make_codons= makeCodons(s4);
for (int ix=0; ix<make_codons.length; ix++) {
al.add(make_codons[ix]);
}if(al.contains("tag")||al.contains("tga")||al.contains("taa")){ }
else{
System.out.println("An ORF found :)\n" + s4);
}
make_codons= makeCodons(s5);
for (int ix=0; ix<make_codons.length; ix++) {
al.add(make_codons[ix]);
} if(al.contains("tag")||al.contains("tga")||al.contains("taa")){ }
else{
System.out.println("An ORF found :)\n" + s5);
}
make_codons= makeCodons(s6);
for (int ix=0; ix<make_codons.length; ix++) {
al.add(make_codons[ix]);
}if(al.contains("tag")||al.contains("tga")||al.contains("taa")){ }
else{
System.out.println("An ORF found :)\n" + s6);
}
}
[LIST=2]
Then in another method named displayFasta(), i have to display the sequence of DNA in fasta format, given the name of the sequence and the sequence. In the fasta format,
- The name should be followed by the tokenizer ">", followed by the sequence. I have achieved that.
The number of characters in each line should be less than 80. Then the control should shift to the next line.How to achieve this?
[LIST]
Code:
String displayInFasta(){
String b=new String();
b= name.concat(">");
return b.concat(seq).toUpperCase();
}
- MOST IMPORTANT:
The number of amino acids formed is quite less than the number of codons. Why so? While an amino acid is formed against each gene, except one stop codon that is present at the end of the gene.
Code:
String[] makeCodons(String gene){
String make_codons[]= new String[(gene.length()/3)];
int b=0;
for( int a=0; a<gene.length()-(gene.length()%3); a+=3){
make_codons[b]= gene.substring(a, a+3);
//System.out.println(make_codons[b]);
b++;
}
return make_codons;
}
String toProtein(String gene){
String make_codons[]= new String[(gene.length()/3)];
make_codons= makeCodons(gene);
StringBuilder al = new StringBuilder();
for(int c=0; c<make_codons.length; c++){
if(make_codons[c].equals("atg"))
al= al.append("M");
//System.out.println("Methionine");
else if(make_codons[c].equals("gtt")|| make_codons[c].equals("gtc")|| make_codons[c].equals("gta")|| make_codons[c].equals("gtg"))
al= al.append("V");
//System.out.println("Valine");
else if(make_codons[c].equals("att")|| make_codons[c].equals("atc")|| make_codons[c].equals("ata"))
al= al.append("I");
// System.out.println("Isoleucine");
else if(make_codons[c].equals("ttg")|| make_codons[c].equals("tta")|| make_codons[c].equals("ctg")|| make_codons[c].equals("cta")|| make_codons[c].equals("ctc")|| make_codons[c].equals("ctt"))
al= al.append("L");
//System.out.println("Leucine");
else if(make_codons[c].equals("tct")|| make_codons[c].equals("tcc")|| make_codons[c].equals("tca")|| make_codons[c].equals("tcg")||make_codons[c].equals("agt")|| make_codons[c].equals("agc"))
al= al.append("S");
// System.out.println("Serine");
else if(make_codons[c].equals("cca")|| make_codons[c].equals("ccc")|| make_codons[c].equals("cct")|| make_codons[c].equals("ccg"))
al= al.append("P");
// System.out.println("Proline");
else if(make_codons[c].equals("act")|| make_codons[c].equals("acc")|| make_codons[c].equals("aca")|| make_codons[c].equals("acg"))
al= al.append("T");
//System.out.println("Threonine");
else if(make_codons[c].equals("gct")|| make_codons[c].equals("gcc")|| make_codons[c].equals("gca")|| make_codons[c].equals("gcg"))
al= al.append("A");
//System.out.println("Alanine");
else if(make_codons[c].equals("tat")|| make_codons[c].equals("tac"))
al= al.append("Y");
// System.out.println("Tyrosine");
else if(make_codons[c].equals("cat")|| make_codons[c].equals("cac"))
al= al.append("H");
//System.out.println("Histidine");
else if(make_codons[c].equals("caa")|| make_codons[c].equals("cag"))
al= al.append("Q");
//System.out.println("Glutamine");
else if(make_codons[c].equals("aat")|| make_codons[c].equals("aac"))
al= al.append( "N");
// System.out.println("Asparagine");
else if(make_codons[c].equals("aag")|| make_codons[c].equals("aaa"))
al= al.append( "K");
// System.out.println("Lysine");
else if(make_codons[c].equals("gac")|| make_codons[c].equals("gat"))
al= al.append( "D");
//System.out.println("Aspartic acid");
else if(make_codons[c].equals("gaa")|| make_codons[c].equals("gag"))
al= al.append( "E");
//System.out.println("Glutamic acid");
else if(make_codons[c].equals("tgt")|| make_codons[c].equals("tgc"))
al= al.append( "C");
//System.out.println("Cystine");
else if(make_codons[c].equals("tgg"))
al= al.append("W");
// System.out.println("Tryptophan");
else if(make_codons[c].equals("agt")|| make_codons[c].equals("cga")|| make_codons[c].equals("ctg")|| make_codons[c].equals("cta")|| make_codons[c].equals("cgt")|| make_codons[c].equals("cgg"))
al= al.append( "R");
// System.out.println("Arginine");
else if(make_codons[c].equals("gga")|| make_codons[c].equals("ggc")|| make_codons[c].equals("ggt"))
al= al.append("G");
// System.out.println("Glycine");
else if(make_codons[c].equals("tga")||make_codons[c].equals("taa")||make_codons[c].equals("tag"))
break;
}
return al.toString();}[/COLOR]
[COLOR="#ff00ff"]public static void main(String[] args) {
DNA c= new DNA();
DNA dna= new DNA("BB002260","aggggggatgggggccccccgcgcctccgcgcgcgcgctcgctgcggcgtcgcgcgcgcccccccaaaaaatgagcgcatccgggcgggcggcggtct");
System.out.println("Polypeptide chain:"+ dna.toProtein("atgggggccccccgcgcctccgcgcgcgcgctcgctgcggcgtcgcgcgcgcccccccaaaaaatga
"));
dna.readingFrames();
[/COLOR]
The constructor is
[COLOR="#ff00ff"] DNA(){}
DNA(String name, String seq){
this.name=name;
this.seq=seq;
}
The class is named DNA.