In: Computer Science
Implementation of above code in JAVA:
public class BasicBioinformatics {
// return a String representation of the complement of
the given sequence
public static char[] complement(char[] dna) {
for(int i=0;i<dna.length;i++)
{
if(dna[i]=='C')
{
dna[i]='G';
}
else
if(dna[i]=='G') {
dna[i]='C';
}
else
if(dna[i]=='A') {
dna[i]='T';
}
else
if(dna[i]=='T') {
dna[i]='A';
}
}
return dna;
}
// return a String representation of the complement of
the given sequence
public static String complement(String dna) {
return new
String(complement(dna.toCharArray()));
}
// return the GC-content of the sequence, to double
precision
public static double gcContent(char[] dna) {
int count=0;
for(int i=0;i<dna.length;i++)
{
if(dna[i]=='C')
{
count++;
}
else
if(dna[i]=='G') {
count++;
}
}
double
content=(count*100)/dna.length;
return content;
}
// return the GC-content of the sequence, to double
precision
public static double gcContent(String dna) {
return
gcContent(dna.toCharArray());
}
// return the Hamming distance between the two
sequences
public static int hammingDistance(char[] dna1, char[]
dna2) {
int count=0;
for(int i=0;i<dna1.length;i++)
{
if(dna1[i]!=dna2[i]) {
count++;
}
}
return count;
}
// return the Hamming distance between the two sequences
public static int hammingDistance(String dna1, String
dna2) {
return
hammingDistance(dna1.toCharArray(), dna2.toCharArray());
}
// return an array of boolean values, of length
equivalent to both parameters' lengths,
// containing true in each subscript where the
parameter strings differ, and false where
// they do not differ
public static boolean[] mutationPoints(char[] dna1,
char[] dna2) {
boolean arr[]= new
boolean[dna1.length];
for(int i=0;i<dna1.length;i++) {
if(dna1[i]!=dna2[i]) {
arr[i]=true;
}
else {
arr[i]=false;
}
}
return arr;
}
// return an array of boolean values, of length
equivalent to both parameters' lengths,
// containing true in each subscript where the parameter strings
differ, and false where
// they do not differ
public static boolean[] mutationPoints(String dna1,
String dna2) {
return
mutationPoints(dna1.toCharArray(), dna2.toCharArray());
}
// Calculates and returns the number of times
// each type of nucleotide occurs in a DNA
sequence.
public static int[] nucleotideCounts(char[] dna)
{
int arr[]= new
int[dna.length];
for(int i=0;i<dna.length;i++)
{
arr[i]=(int)dna[i];
}
return arr;
}
// Calculates and returns the number of times
// each type of nucleotide occurs in a DNA
sequence.
public static int[] nucleotideCounts(String dna)
{
return
nucleotideCounts(dna.toCharArray());
}
// return a char array representation of the
reverse
// complement of the given sequence
public static char[] reverseComplement(char[] dna)
{
for(int i=0;i<dna.length;i++) {
if(dna[i]=='C')
{
dna[i]='A';
}
else
if(dna[i]=='G') {
dna[i]='T';
}
else
if(dna[i]=='A') {
dna[i]='C';
}
else
if(dna[i]=='T') {
dna[i]='G';
}
}
return dna;
}
// return a String representation of the reverse
// complement of the given sequence
public static String reverseComplement(String dna)
{
return new
String(reverseComplement(dna.toCharArray()));
}
// driver function or main metjoh
public static void main(String[] args) {
System.out.println("----------- Some following operations are
performed below : ------------");
System.out.println();
char [] dna= {'G','T','C','A'};
char [] dna1= {'A','T','T','A','T','G','C'};
char [] dna2= {'A','T','G','A','T','C','C'};
System.out.print("Complement of ");
print(dna);
System.out.print(" is : ");
print(complement(dna));
System.out.println();
System.out.print("The content of ");
print(dna);
System.out.print(" is :"+gcContent(dna)+"%");
System.out.println();
System.out.print("The hamming Distance between
");
print(dna1);
System.out.print(" and ");
print(dna2);
System.out.print(" is
:"+hammingDistance(dna1,dna2));
System.out.println();
System.out.print("The mutation between ");
print(dna1);
System.out.print(" and ");
print(dna2);
System.out.print(" is : ");
boolean arr[]=mutationPoints(dna1,dna2);
for(int i=0;i<arr.length;i++) {
System.out.print(arr[i]+",");
}
System.out.println();
System.out.print("The nucleotide Counts of ");
print(dna1);
System.out.print(" is : ");
int[] arr2=nucleotideCounts(dna1);
for(int i=0;i<arr2.length;i++) {
System.out.print(arr2[i]+",");
}
System.out.println();
System.out.print("The Reverse Complement of ");
print(dna);
System.out.print(" is : ");
print(reverseComplement(dna));
}
static void print(char arr[])
{
for(int
i=0;i<arr.length;i++) {
System.out.print(arr[i]);
}
}
}
SAMPLE OUTPUT:
If you have any doubt regarding this question please ask me in comments
// THANK YOU:-)