In: Computer Science
Code
/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author JOSEE
*/
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)
{
int i, k;
char temp;
int size=dna.length;
//reverse the dna array
for (i = 0; i < size / 2; i++) {
temp = dna[i];
dna[i] = dna[size - i - 1];
dna[size - i - 1] = temp;
}
//then change DNA sequences to its complements
for (i = 0; i < size ; i++)
{
if(dna[i]=='A')
dna[i]='T';
else if(dna[i]=='T')
dna[i]='A';
else if(dna[i]=='C')
dna[i]='G';
else if(dna[i]=='G')
dna[i]='C';
}
return dna;
}
/**
* 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()));
}
}
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.