title: Debugging/Decoding DNA Java
body: <p>I'm trying to debug my program for errors; for example the error <code>incompatible types: edu.duke.StorageResource cannot be converted to java.lang.String</code> on the line <code>String geneList = FMG.storeAll(dna);</code> what does it mean?. </p>
  
  <p>The storeAll and printGenes methods is what I'm having trouble with. I can't seem to get the syntax right for storing genes. I have a basic outline of what it should look like but I don't know how to use the StorageResource properly. Also in the printGenes method, I don't know what is needed so all of my desired print statements execute. Specifically I'd like to know (what the syntax is of) how to count up the number of genes, count the characters in the DNA strand, etc.. Also I have a problem with the location of where I should call the methods that I have already created; I want to know the exact location, in the code. Any suggestions would be greatly appreciated. </p>
  
  <p>(PS: The main method has been changed to <code>printGenes</code> method, because my class uses BlueJ in which you can't call Main methods.</p>
  
  <p>Here is where you can download the file necessary to do this assignment, <a href="http://www.dukelearntoprogram.com/course2/data/dna.zip" rel="nofollow">http://www.dukelearntoprogram.com/course2/data/dna.zip</a>
  Any suggestions are helpful.  </p>
  
  <p>Here's my faulty code: </p>
  
  <pre><code>import java.io.*;
  import edu.duke.FileResource;
  import edu.duke.StorageResource;
  import edu.duke.DirectoryResource;
  
  public class FindMultiGenes5 {
      public int findStopIndex(String dna, int index) {
          int stop1 = dna.indexOf("TGA", index);
          if (stop1 == -1 || (stop1 - index) % 3 != 0) {
              stop1 = dna.length();
          }
          int stop2 = dna.indexOf("TAA", index);
          if (stop2 == -1 || (stop2 - index) % 3 != 0) {
              stop2 = dna.length();
          }
          int stop3 = dna.indexOf("TAG", index);
          if (stop3 == -1 || (stop3 - index) % 3 != 0) {
              stop3 = dna.length();
          }
          return Math.min(stop1, Math.min(stop2, stop3));
      }
  
      public StorageResource storeAll(String dna) {
  
          //CATGTAATAGATGAATGACTGATAGATATGCTTGTATGCTATGAAAATGTGAAATGACCCAdna = "CATGTAATAGATGAATGACTGATAGATATGCTTGTATGCTATGAAAATGTGAAATGACCCA";
  
          String sequence = dna.toUpperCase();
          StorageResource store = new StorageResource();
          int index = 0;
  
  
          while (true) {
              index = sequence.indexOf("ATG", index);
              if (index == -1)
                  break;
  
              int stop = findStopIndex(sequence, index + 3);
  
              if (stop != sequence.length()) {
                  String gene = dna.substring(index, stop + 3);
                  store.add(gene);
  
                  System.out.println("From: " + index + " to " + stop + " Gene: " + gene );//index = sequence.substring(index, stop + 3).length();
              index = stop + 3; // start at the end of the stop codon
            }else{  index = index + 3;
          }
  
      }
      return store;//System.out.println(sequence);
      }
     public void testStorageFinder() {
        DirectoryResource dr = new DirectoryResource();
        StorageResource dnaStore = new StorageResource(); 
      for (File f : dr.selectedFiles()) {
          FileResource fr = new FileResource(f);
          String s = fr.asString();
          dnaStore = storeAll(s);
          printGenes(dnaStore);
      }
  
  
          System.out.println("size = " + dnaStore.size());
  
      }  
    public String readStrFromFile(){
  
          FileResource readFile = new FileResource();
  
          String DNA = readFile.asString();
  
          //System.out.println("DNA: " + DNA);
  
          return DNA;
  
      }//end readStrFromFile() method;
    public float calCGRatio(String gene){
  
          gene = gene.toUpperCase();  
          int len = gene.length();
          int CGCount = 0;
  
          for(int i=0; i&lt;len; i++){
  
              if(gene.charAt(i) == 'C' || gene.charAt(i) == 'G')
                  CGCount++;
  
          }//end for loop
  
          System.out.println("CGCount " + CGCount + " Length: " + len + " Ratio: " + (float)CGCount/len);
          return (float)CGCount/len;
      }//end of calCGRatio() method;
      public void printGenes(StorageResource sr){
     for(String gene: sr.data()){
       if (gene.length() &gt; 60) {
         System.out.println(gene.length()+"\t"+gene);
       }
       if(calCGRatio(gene)&gt; 0.35) {
         System.out.println(gene.length()+"\t"+gene);
        }
    }
  
          //create a FindMultiGenesFile object FMG
          FindMultiGenes5 FMG = new FindMultiGenes5();
  
          //read a DNA sequence from file
          String dna = FMG.readStrFromFile();
  
          String geneList = FMG.storeAll(dna);
  
          //store all genes into a document
          StorageResource dnaStore = new StorageResource();
  
          System.out.println("\n There are " + geneList.size() + " genes. ");
  
          int longerthan60 = 0;
          int CGGreaterthan35 = 0;
          for(int i=0; i&lt;geneList.size(); i++){
  
              if(!dnaStore.contains(geneList.get(i)))
                  dnaStore.add(geneList.get(i));
  
              if(geneList.get(i).length() &gt; 60) longerthan60++;
              if(FMG.calCGRatio(geneList.get(i)) &gt; 0.35) CGGreaterthan35++;
  
          }
  
          System.out.println("dnaStore.size: " + dnaStore.size());
  
  
          System.out.println("\n There are " + dnaStore.size() + " genes. ");
          System.out.println("There are " + longerthan60 + " genes longer than 60.");
          System.out.println("There are " + CGGreaterthan35 + " genes with CG ratio greater than 0.35.");
      }//end main();
  }
  </code></pre>