/** * A method that indicates the end of a gene, which is found in a dna. * * @param dna The dna strand to search for gene's end. * @param startIndex The index of the searching start. * @return The index of end. */ public int stopIndex(String dna, int startIndex) { int stopTAG = dna.indexOf("TAG", startIndex); if (stopTAG == -1 || (stopTAG - startIndex) % 3 != 0) stopTAG = dna.length(); int stopTGA = dna.indexOf("TGA", startIndex); if (stopTGA == -1 || (stopTGA - startIndex) % 3 != 0) stopTGA = dna.length(); int stopTAA = dna.indexOf("TAA", startIndex); if (stopTAA == -1 || (stopTAA - startIndex) % 3 != 0) stopTAA = dna.length(); return Math.min(stopTAG + 3, Math.min(stopTGA + 3, stopTAA + 3)); }
/** * 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; }
/** * A method that calculates the CG ratio. * * @param dna The dna strand to search for genes. * @return The CG Ratio. */ public float cgRatio(String dna) { dna = dna.toUpperCase(); int i = 0, counter = 0; while (true) { int cid = dna.indexOf("C", i); if (cid == -1) cid = dna.length() + 1; int gid = dna.indexOf("G", i); if (gid == -1) gid = dna.length() + 1; int pos = Math.min(cid, gid); if (pos == dna.length() + 1) break; else counter++; i = pos + 1; } return (float) counter / dna.length(); }