/** * A method that finds all genes in a dna strand strarting with ATG coden and ending with TAG, TGA * or TAA coden. * * @param dna The dna strand to search for genes. * @return all found genes in StorageResource datatype. */ public StorageResource storeAll(String dna) { StorageResource sr = new StorageResource(); int start = 0; int stop = 0; int loc = 0; String dna1 = dna.toUpperCase(); // System.out.println(dna1); while (true) { loc = dna1.indexOf("ATG", start); if (loc == -1) break; int sloc = stopIndex(dna1, loc + 3); if (sloc > dna.length()) { // continue; // System.out.println(""); } else { sr.add(dna.substring(loc, sloc)); // System.out.println(dna.substring(loc,sloc)); loc = sloc - 3; } // System.out.println(loc); start = loc + 3; } return sr; }
public void testStorageFinder() { String dnaString = ""; // FileResource dna = new FileResource("dna/brca1line.fa"); FileResource dna = new FileResource("dna/GRch38dnapart.fa"); dnaString = dna.asString(); // String dnaString="ATGCCATAG"; StorageResource sr = storeAll(dnaString); printGenes(sr); System.out.println("Number of genes: " + sr.size()); System.out.println("Number of CTG : " + ctgCounter(dnaString)); System.out.println("The length of longer gene is : " + longestGene(sr)); }
/** * A method that find the length of longest gene. * * @param genes The genes of a dna strand. * @return The Length of longer gene. */ public int longestGene(StorageResource sr) { int maxlength = 0; for (String a : sr.data()) { maxlength = Math.max(a.length(), maxlength); } return maxlength; }
public void printGenes(StorageResource sr) { int counter60 = 0; int counter035 = 0; for (String a : sr.data()) { if (a.length() > 60) { System.out.println("String length longer than 60 : " + a); counter60++; } if (cgRatio(a) > 0.35) { System.out.println("CG Ratio greater than 0.35 : " + a); counter035++; } } System.out.println("Number of elements with length greater than 60 : " + counter60); System.out.println("Number of elements with CG ratio greater than 0.35 : " + counter035); }