In: Computer Science
A base-paired DNA sequence is one where A's line up with T's and G's line up with C's. For example:
base-paired DNA sequence ATCGAT TAGCTA
If A is not paired with T, T with A, G with C, or C with G, then the sequence is not base-paired. For example:
not a base-paired DNA sequence
ATCGAT TAGCAA
not a base-paired DNA sequence ATCGAT TATCTA
A base-paired sequence also needs both sides to have the same length. For example,
not a base-paired DNA sequence ATCG TAGCTA
Write a method base_check that takes two Strings as arguments and returns true if and only if the DNA sequence represented by the Strings is base-paired. Implement your solution in the file we have provided: BaseCheck.java. Your program should run and print only “Tests pass for base_check” in the console. It is your responsibility to make sure the program runs properly in IntelliJ.
Tips You will find the following String functions helpful • s.charAt(i), returns the ith character in the String s • s.length(), returns the number of characters in the String s
public class BaseCheck { public static void main(String[] args) { String seqA1 = "ATCGATTGAGCTCTAGCG"; String seqB1 = "TAGCTAACTCGAGATCGC"; if (!base_check(seqA1, seqB1)) { System.out.println("FAILED TEST 1"); System.exit(1); } String seqA2 = "ATCGATGGAGCTGTAGCG"; String seqB2 = "TAGCTAACTCGAGATCGA"; if (base_check(seqA2, seqB2)) { System.out.println("FAILED TEST 2"); System.exit(1); } String seqA3 = "ATCGATTGAGCT"; String seqB3 = "TAGCTAACTCGAGATCGC"; if (base_check(seqA3, seqB3)) { System.out.println("FAILED TEST 3"); System.exit(1); } String seqA4 = "ATCGATTGAGCTCTAGCG"; String seqB4 = "TAGCTAACTCGAGATC"; if (base_check(seqA4, seqB4)) { System.out.println("FAILED TEST 4"); System.exit(1); } String seqA5 = "ATCGATTGAGCTCTAGCG"; String seqB5 = "ATCGATTGAGCTCTAGCG"; if (base_check(seqA5, seqB5)) { System.out.println("FAILED TEST 5"); System.exit(1); } String seqA6 = "GGGG"; String seqB6 = "CCCC"; if (!base_check(seqA6, seqB6)) { System.out.println("FAILED TEST 6"); System.exit(1); } /* We will test your code on additional test cases, so make sure it really works. (e.g., you can add more of your own test cases, just copy one of the above ones and modify it). */ System.out.println("Tests pass for base_check"); } public static boolean base_check(String seq1, String seq2) { /* Your solution here; replace the following code with yours */ return false; } }
public class BaseCheck { public static void main(String[] args) { String seqA1 = "ATCGATTGAGCTCTAGCG"; String seqB1 = "TAGCTAACTCGAGATCGC"; if (!base_check(seqA1, seqB1)) { System.out.println("FAILED TEST 1"); System.exit(1); } String seqA2 = "ATCGATGGAGCTGTAGCG"; String seqB2 = "TAGCTAACTCGAGATCGA"; if (base_check(seqA2, seqB2)) { System.out.println("FAILED TEST 2"); System.exit(1); } String seqA3 = "ATCGATTGAGCT"; String seqB3 = "TAGCTAACTCGAGATCGC"; if (base_check(seqA3, seqB3)) { System.out.println("FAILED TEST 3"); System.exit(1); } String seqA4 = "ATCGATTGAGCTCTAGCG"; String seqB4 = "TAGCTAACTCGAGATC"; if (base_check(seqA4, seqB4)) { System.out.println("FAILED TEST 4"); System.exit(1); } String seqA5 = "ATCGATTGAGCTCTAGCG"; String seqB5 = "ATCGATTGAGCTCTAGCG"; if (base_check(seqA5, seqB5)) { System.out.println("FAILED TEST 5"); System.exit(1); } String seqA6 = "GGGG"; String seqB6 = "CCCC"; if (!base_check(seqA6, seqB6)) { System.out.println("FAILED TEST 6"); System.exit(1); } /* * We will test your code on additional test cases, so make sure it really * works. (e.g., you can add more of your own test cases, just copy one of the * above ones and modify it). */ System.out.println("Tests pass for base_check"); } public static boolean base_check(String seq1, String seq2) { if(seq1.length() != seq2.length()) { return false; } int size = seq1.length(); int i = 0; while(i < size) { char c1 = seq1.charAt(i); char c2 = seq2.charAt(i); i++; if(c1 == c2) { return false; } if((c1 == 'A' && c2 == 'T') || (c1 == 'T' && c2 == 'A')) { continue; } if((c1 == 'G' && c2 == 'C') || (c1 == 'C' && c2 == 'G')) { continue; } return false; } return true; } }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.