input then the program will compute the fraction of nucleotides in both sequence
ID: 3885887 • Letter: I
Question
input then the program will compute the fraction of nucleotides in both sequences that are shared. Consider the following example: Sequence 1: GCGTTAGCTAAAGCC Sequence 2: CCGTAAGCTATACCG The sequence identity ID1,2 between sequences 1 and 2 is calculated with the following equation: 1,2 where L is the length of the sequence, Ng s the nucleotide at position the function (A, B) equals l if A and B are the same nucleotide or 0 otherwise . A he example shown before, ID,1,2 0.73 since the two sequences share 11 identical nucleotides in t i E 1... L in sequence 1 For t same position and L = 15. Program Structure You program should do the following: 1. Ask the user to input sequences one amino acid at a time. To simplify the problem we will 2. The program should verify that the input nucleotides are only A, G, c,T,U. Otherwise it should retur that the sequence length must be L 10. The program should only accept or ask for 10 characters. an error and ask the user to input the right nucleotideExplanation / Answer
Let's re-write the function (Niseq1, Niseq2), as (seq1, seq2, i), where length of seq1 = length of seq2 = L
This function (seq1, seq2, i) will return 1, if the characters at ith position in both the sequences, seq1 and seq2, are equal. Otherwise, it will return 0.
(i=1 to L)(seq1, seq2, i), means to check for each position in the sequences (from i=1 to i=L), and add up the results. Finally we divide the above result by length (L) of the sequences to get the sequence identity/match.
To implment the above formual, you need to use the following steps
1. initialize ID12 = 0.0
2. for i = 1 to 10
3. If character at ith position in seq1 == character at ith position in seq2
4. ID12 = ID12 + 1
5. endIf
6. endfor
7. result = (ID12)/ L
Below is the working code of the requested program in JAVA
------------------------------------------------------------------------------------------
import java.util.Scanner;
public class DNAMatch {
/*
* Function that finds out the sequence identity
*/
public static double findSequenceIDentity(String seq1, String seq2, int L) {
double iD12 = 0.0;
for (int i=0; i<L; i++) {
if (seq1.charAt(i) == seq2.charAt(i)) {
iD12 += 1;
}
}
return (iD12 / L);
}
/*
* main method
*/
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int L = 10;
System.out.println("Enter Sequence-1, (one character at a time) : ");
String seqOne = getInputSequence(scanner, L);
System.out.println("Enter Sequence-2, (one character at a time) : ");
String seqTwo = getInputSequence(scanner, L);
System.out.println(" Sequence-1 is " + seqOne + " Sequence-2 is " + seqTwo);
System.out.println("Sequence Identity of (1,2) is " + findSequenceIDentity(seqOne, seqTwo, L));
}
public static String getInputSequence(Scanner scanner, int L) {
StringBuilder sequence = new StringBuilder();
for (int i=1; i<=L; i++) {
String character = scanner.next().trim().toUpperCase();
/*
* Read only if one character is entered
* */
if (character.length() == 1) {
if (character.equals("A") || character.equals("G") ||
character.equals("C") || character.equals("T") || character.equals("U")) {
sequence.append(character);
}
else {
i--;
System.out.println("Invalid Character!");
}
}
else {
i--;
}
}
return sequence.toString();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.