JAL-1140 use the Reader provided by the jalview.io.FileParse framework
[jalview.git] / src / jalview / io / RnamlFile.java
index e614e6b..c93201f 100644 (file)
@@ -10,6 +10,7 @@ import jalview.datamodel.SecondaryStructureAnnotation;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.ws.jws1.Annotate3D;
 
 import java.io.BufferedReader;
 import java.io.FileNotFoundException;
@@ -35,7 +36,9 @@ import com.stevesoft.pat.Regex;
 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
+import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
 import fr.orsay.lri.varna.factories.RNAFactory;
+import fr.orsay.lri.varna.factories.RNAFactory.RNAFileType;
 import fr.orsay.lri.varna.models.rna.RNA;
 import fr.orsay.lri.varna.utils.RNAMLParser;
 
@@ -45,6 +48,7 @@ import fr.orsay.lri.varna.utils.RNAMLParser;
 public class RnamlFile extends AlignFile
 {
         public String id;
+        protected ArrayList<RNA> result;
         
         public RnamlFile()
          {
@@ -52,36 +56,110 @@ public class RnamlFile extends AlignFile
                
          }
         
-        public RnamlFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
+        public RnamlFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
          {
            super(inFile, type);
            
          }
 
-         public RnamlFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
+         public RnamlFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
          {
            super(source);
            
          }
          
+//       public RnamlFile(BufferedReader r) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
+//       {
+//                     super();            
+//                 parse(r);
+//                 // sets the index of each sequence in the alignment
+//                 for( int i=0,c=seqs.size(); i<c; i++ ) {  
+//                     seqs.get(i).setIndex(i);  
+//                 }
+//               
+//         
+//       }
          
+       public BufferedReader CreateReader() throws FileNotFoundException
+       {
+                FileReader fr = null;
+                 fr = new FileReader(inFile); 
+                 
+                 BufferedReader r = new BufferedReader (fr);
+                 return r;
+       }
        
        
-         public void parse() throws ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax, FileNotFoundException 
-         {
-                 System.out.println("this is a rnaml file");
+       @SuppressWarnings("unchecked")
+       public void parse() throws FileNotFoundException, ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
+       {
+                result = RNAFactory.loadSecStrRNAML(getReader());
                  
+                System.out.println("this is the secondary scructure:" +result.size());
+                 //System.out.println("this is the secondary scructure:" +result.toString());
+                 //System.out.println("this is the secondary scructure:" +result.size());
+                SequenceI[] seqs = new SequenceI[result.size()];
+                 System.out.println(type); //the type is "File"
+                 System.out.println(inFile );//inFile is the path
                  
-                 FileReader fr = null;
-                 fr = new FileReader(inFile); 
+                for(int i=0;i<result.size();i++)
+                       {
+                        RNA current = result.get(i);
+                 System.out.println(current.getSeq());
+                 //System.out.println(result.get(i).getStructBPSEQ());
+                 System.out.println(result.get(i).getStructDBN(true));
+                 System.out.println(i);
+                 String rna =current.getStructDBN(true);
+                 //System.out.println(result.get(0).getAnnotations());
+                 String seq = current.getSeq();
+       
+                 int begin=0;
+                 int end = seq.length()-1;
                  
-                 BufferedReader r = new BufferedReader (fr);
+                 id = safeName(getDataName());
+                 seqs[i] = new Sequence(id, seq, begin, end);
+                 //System.out.println(seq);
+                 System.out.println("Rna is still "+rna);
+                 //SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
+                 //seqs[i].addSequenceFeature(feat);
+                 
+                 String[] annot=new String[rna.length()] ;
+                 Annotation[] ann = new Annotation[rna.length()];
+               
+                 for(int j=0;j<rna.length();j++)
+                       {
+                         annot[j] =rna.substring(j,j+1);
+                 
+                       }
+                 
+                 for(int k=0;k<rna.length();k++)
+               {
+                         ann[k] = new Annotation(annot[k], "", jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0), 0f);
+                                                 
+               }
+                 AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",current.getID(),ann);
+                 
+                 seqs[i].addAlignmentAnnotation(align);
+                 seqs[i].setRNA(result.get(i));
+                 this.annotations.addElement(align);
+               }
+         this.setSeqs(seqs);
                 
+                
+               
+
+       }
+         
+       
+         public void parse(BufferedReader r) throws ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax 
+         {
+                  System.out.println("parse with Buffer (RnamlFile");
                  Hashtable seqhash = new Hashtable();
                  Vector headers = new Vector();
                  //ArrayList<String> seq =new ArrayList();
-                 System.out.println(r);
-                 ArrayList<RNA> result = RNAFactory.loadSecStrRNAML(r);
+                 //System.out.println(r);
+                 
+                 result = RNAFactory.loadSecStr(r,RNAFileType.FILE_TYPE_RNAML);
                  
                  System.out.println("this is the secondary scructure:" +result.toArray());
                  System.out.println("this is the secondary scructure:" +result.toString());
@@ -110,7 +188,7 @@ public class RnamlFile extends AlignFile
                  for(int j=0;j<rna1.length();j++)
                        {
                  annot[j] =rna1.substring(j,j+1);
-                 System.out.println(annot[j]);
+                 //System.out.println(annot[j]);
                        }
                  
                  for(int k=0;k<rna1.length();k++)
@@ -124,8 +202,9 @@ public class RnamlFile extends AlignFile
                  seqs[0].addAlignmentAnnotation(align);
                  this.annotations.addElement(align);
                }
+               //Annotate3D tintin = new Annotate3D();
                  
-                 
+               //System.out.println(tintin);  
                  
                  
                  
@@ -268,5 +347,13 @@ public class RnamlFile extends AlignFile
            return dataName;
          }
          
+         public ArrayList getRNA()
+         {
+                 return result;
+         }
+         
+         public Vector getAnnot()
+         {
+                 return annotations;
+         }
 }
-