Monday, February 2, 2015

GeneFind.java in progrme



GeneFind.java

public class GeneFind
{
    public static void main(String[] args) 
   {
        String start = args[0];
        String stop  = args[1];
        String genome = StdIn.readAll();
        System.out.println("genome = '" + genome + "'");
        System.out.println("start  = '" + start  + "'");
        System.out.println("stop   = '" + stop   + "'");
        int beg = -1;
        for (int i = 0; i < genome.length() - 2; i++)
        {
            String codon = genome.substring(i, i+3);
            if (codon.equals(start)) beg = i;

            if ((codon.equals(stop)) && (beg != -1) && (beg + 3 < i))
               {
                String gene = genome.substring(beg+3, i);
                if (gene.length() % 3 == 0)
               {
                    System.out.println(gene);
                    beg = -1;
                }
            }
        }
    }
}

No comments:

Post a Comment