GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — java-coding-problems/DNASequenceDecoder.java at main · GitH05/java-coding-problems Expand file tree/ Copy pathDNASequenceDecoder.javaMore file actions 43 lines (36 loc) · 1.87 KB / Copy pathDNASequenceDecoder.javaFile metadata and controls43 lines (36 loc) · 1.87 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 import java.util.*; public class DNASequenceDecoder { public static String extractDNABases(String sequenceBinary) { // Checking if the string starts with the DNA identifier if (!sequenceBinary.startsWith("000")) { return ""; } // Define the binary to nucleic base mapping Map<String, String> binaryToBase = new HashMap<>(); binaryToBase.put("011", "A"); binaryToBase.put("010", "G"); binaryToBase.put("001", "C"); binaryToBase.put("101", "T"); binaryToBase.put("110", "U"); // Removing the '000' DNA prefix String dnaBits = sequenceBinary.substring(3); //substring extract the given index like( o to 3-1) StringBuilder result = new StringBuilder(); // System.out.println(binaryToBase.get("A")); // System.out.println(binaryToBase.get("110")); // Reading the bits in chunks of 3 that used to compare with each key for (int i = 0; i <= dnaBits.length() - 3; i += 3) { //dnaBits.length()-3 == avoid lengthBound error String triplet = dnaBits.substring(i, i + 3); //triplets store the extract values by substring(0,0+3 -1) String base = binaryToBase.getOrDefault(triplet, ""); //base stores and compare the value existences if (base.equals("U")) { base = "T"; //if there is "U" then it should be replaced by "T" } result.append(base); //All the pairs stored accordingly in the result } return result.toString(); //return the final nucleicbase in string } public static void main(String[] args) { String sequenceBinary = "000001001011101010010110011"; String result = extractDNABases(sequenceBinary); System.out.println("Nucleic Base Sequence: " + result); // Output: AGCTT } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |