In: Computer Science
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
BasicBioinformatics.java
package staticclasses;
public class BasicBioinformatics {
/**
* Calculates and returns the reverse complement of a
DNA sequence. In DNA sequences, 'A' and 'T'
* are complements of each other, as are 'C' and 'G'.
The reverse complement is formed by
* reversing the symbols of a sequence, then taking the
complement of each symbol (e.g., the
* reverse complement of "GTCA" is "TGAC").
*
* @param dna a char array representing a DNA sequence
of arbitrary length, containing only the
* characters A, C, G and T
*
* @return a char array representation of the reverse
complement of the given sequence
*/
public static char[] reverseComplement(char[] dna)
{
char res[] = new
char[dna.length];
int count=0;
for (int i =dna.length-1 ; i >=
0; i--) {
if(dna[i]=='A')
{
res[count]='T';
}else
if(dna[i]=='T') {
res[count]='A';
}else
if(dna[i]=='C') {
res[count]='G';
}else
if(dna[i]=='G') {
res[count]='C';
}
count++;
}
return res;
}
/**
* Calculates and returns the reverse complement of a
DNA sequence. In DNA sequences, 'A' and 'T'
* are complements of each other, as are 'C' and 'G'.
The reverse complement is formed by
* reversing the symbols of a sequence, then taking the
complement of each symbol (e.g., the
* reverse complement of "GTCA" is "TGAC").
*
* @param dna a string representing a DNA sequence of
arbitrary length, containing only the
* characters A, C, G and T
*
* @return a String representation of the reverse
complement of the given sequence
*/
public static String reverseComplement(String dna)
{
return new
String(reverseComplement(dna.toCharArray()));
}
public static void main(String[] args) {
System.out.println("reverseComplement(\"GTCA\") converted to :
"+reverseComplement("GTCA"));
System.out.println("reverseComplement(\"TAAC\") converted to :
"+reverseComplement("TAAC"));
}
}