Question & Answer: 1) how to concatenate DNA sequences as arguments and return the concatenated sequences…..

java

1) how to concatenate DNA sequences as arguments and return the concatenated sequences

2) how to swap the contents of an array that has 6 elements at indexes 1 and 2.

3) biojava to reverse complmement a DNA strand and give it variable rev_com.

Expert Answer

 

package artifact1;

import org.biojava.nbio.core.exceptions.CompoundNotFoundException;

import org.biojava.nbio.core.sequence.DNASequence;

public class Main {

public static void main(String[] args) {

try {

DNASequence sequence1 = new DNASequence(“gtccttcttatcaaaacaacaccga”);

DNASequence sequence2 = new DNASequence(“gcaaagtcgagagggacttatccgc”);

System.out.println(“Sequence 1 : ” + sequence1.toString());

System.out.println(“Sequence 2 : ” + sequence2.toString());

// Concatenate DNA sequences

DNASequence combined = concatDNAsequences(sequence1, sequence2);

System.out.println(“Concatenated sequence is : ”

+ combined.toString());

// Swap elements of array

int array1[] = { 205, 306, 59, 89, 452, 10 };

System.out.println(“Before swap : “);

displayArray(array1);

int temp = array1[1];

array1[1] = array1[2];

array1[2] = temp;

System.out.println(“After swap : “);

displayArray(array1);

// Reverse complement DNA sequence

DNASequence rev_com = reverseComplement(sequence1);

System.out.println(“Reverse complemenet of sequence 1 is : ”

+ rev_com);

} catch (CompoundNotFoundException e) {

e.printStackTrace();

System.out.println(“Error !!!!”);

}

}

public static DNASequence concatDNAsequences(DNASequence seq1,

DNASequence seq2) {

StringBuffer sb = new StringBuffer(seq1.toString());

sb.append(seq2.toString());

try {

DNASequence result = new DNASequence(sb.toString());

return result;

} catch (CompoundNotFoundException e) {

e.printStackTrace();

return new DNASequence();

}

}

public static DNASequence reverseComplement(DNASequence seq) {

try {

return new DNASequence(seq.getReverseComplement()

.getSequenceAsString());

} catch (CompoundNotFoundException e) {

e.printStackTrace();

return new DNASequence();

}

}

public static void displayArray(int[] arr) {

for (int i = 0; i < arr.length; i++) {

System.out.print(arr[i]);

if (i != arr.length – 1) {

System.out.print(“,”);

}

}

System.out.println();

}

}

OUTPUT:

Sequence 1 : gtccttcttatcaaaacaacaccga
Sequence 2 : gcaaagtcgagagggacttatccgc
Concatenated sequence is : gtccttcttatcaaaacaacaccgagcaaagtcgagagggacttatccgc
Before swap :
205,306,59,89,452,10
After swap :
205,59,306,89,452,10
Reverse complemenet of sequence 1 is : tcggtgttgttttgataagaaggac

Still stressed from student homework?
Get quality assistance from academic writers!