7 import jalview.datamodel.AlignmentAnnotation;
8 import jalview.datamodel.Annotation;
9 import jalview.datamodel.SecondaryStructureAnnotation;
10 import jalview.datamodel.Sequence;
11 import jalview.datamodel.SequenceFeature;
12 import jalview.datamodel.SequenceI;
14 import java.io.BufferedReader;
15 import java.io.FileNotFoundException;
16 import java.io.IOException;
17 import java.io.Reader;
18 import java.io.FileReader;
19 import java.lang.reflect.Array;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.Hashtable;
23 import java.util.List;
24 import java.util.Vector;
26 import javax.xml.parsers.ParserConfigurationException;
27 import javax.xml.parsers.SAXParser;
28 import javax.xml.parsers.SAXParserFactory;
30 import org.xml.sax.InputSource;
31 import org.xml.sax.SAXException;
33 import com.stevesoft.pat.Regex;
35 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
36 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
37 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
38 import fr.orsay.lri.varna.factories.RNAFactory;
39 import fr.orsay.lri.varna.models.rna.RNA;
40 import fr.orsay.lri.varna.utils.RNAMLParser;
45 public class RnamlFile extends AlignFile
55 public RnamlFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
61 public RnamlFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
70 public void parse() throws ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax, FileNotFoundException
72 System.out.println("this is a rnaml file");
76 fr = new FileReader(inFile);
78 BufferedReader r = new BufferedReader (fr);
80 Hashtable seqhash = new Hashtable();
81 Vector headers = new Vector();
82 //ArrayList<String> seq =new ArrayList();
83 System.out.println(r);
84 ArrayList<RNA> result = RNAFactory.loadSecStrRNAML(r);
86 System.out.println("this is the secondary scructure:" +result.toArray());
87 System.out.println("this is the secondary scructure:" +result.toString());
88 System.out.println("this is the secondary scructure:" +result.size());
89 for(int i=0;i<result.size();i++)
91 System.out.println(result.get(0).getSeq());
92 System.out.println(result.get(0).getStructBPSEQ());
93 System.out.println(result.get(0).getStructDBN(true));
94 String rna1 =result.get(0).getStructDBN(true);
95 System.out.println(result.get(0).getAnnotations());
96 String seq = result.get(0).getSeq();
97 System.out.println(type); //the type is "File"
98 System.out.println(inFile );//inFile is the path
100 int end = seq.length()-1;
101 SequenceI[] seqs = new SequenceI[1];
102 id = safeName(getDataName());
103 seqs[0] = new Sequence(id, seq, begin, end);
104 SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
105 seqs[0].addSequenceFeature(feat);
108 String[] annot=new String[10000] ;
109 Annotation[] ann = new Annotation[1000];
110 for(int j=0;j<rna1.length();j++)
112 annot[j] =rna1.substring(j,j+1);
113 System.out.println(annot[j]);
116 for(int k=0;k<rna1.length();k++)
118 ann[k] = new Annotation(annot[k], "", ' ', 0f);
120 ann[k].secondaryStructure = jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0);
123 AlignmentAnnotation align = new AlignmentAnnotation("Secondary structure","",ann);
124 seqs[0].addAlignmentAnnotation(align);
125 this.annotations.addElement(align);
137 // for(RNAMLParser.RNATmp rnaTmp : RNAMLData.getMolecules())
139 // // Retrieving parsed data
140 // seq = rnaTmp.getSequence(); //contient la séquence sous forme de liste
141 // System.out.println(seq);
142 // String seqAsStr = "";
145 // // Only consider last character, e.g. in case of modified nucleotide
146 // seqAsStr += s.charAt(s.length()-1);
149 // int end = seqAsStr.length()-1;
150 // SequenceI[] seqs = new SequenceI[1];
151 // id = safeName(getDataName());
152 // seqs[0] = new Sequence(id, seqAsStr, begin, end);
153 // SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
155 // seqs[0].addSequenceFeature(feat);
156 // this.setSeqs(seqs);
158 //String pos = annot.substring(1, 2);
159 //System.out.println(annot);
160 //System.out.println(pos);
162 // ann[1] = new Annotation(pos, "", ' ', 0f);
163 // ann[1].secondaryStructure = 'A';
164 //System.out.println(ann[1]);
166 // toto.annotations=ann;
170 //// Annotation[] els = new Annotation[seq.size()];
172 // //System.err.println(""+seq.size());
173 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
174 // String[] annot = new String[10000];
176 // //Annotation[] ann = new Annotation[allbpsTmp.size()];
177 // for (int i = 0; i < allbpsTmp.size(); i++) {
178 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
179 // //System.err.println("toto ="+bp);
180 // int bp5 = bp.pos5;
182 // //annot[bp5]= '(';
183 // System.out.println(annot[bp5]);
184 // //System.out.println("bp5 ="+bp5);
185 // int bp3 = bp.pos3;
188 // System.out.println(annot[bp3]);
189 // //System.out.println(annot.get(bp3));
191 // //String pos1 = annot.substring(bp5, bp5+1);
192 // //String pos2 = annot.substring(bp3, bp3+1);
193 // //ann[i] = new Annotation(pos1, "", ' ', 0f);
194 // //ann[i+1] = new Annotation(pos2, "", ' ', 0f);
195 // //System.out.println(pos1);
197 // //System.out.println("bp3 ="+bp3);
198 // //ModeleBP newStyle = bp.createBPStyle(mb, part);
200 // Annotation[] ann = new Annotation[annot.length+1];
201 // for(int i=0;i<annot.length;i++)
203 // if(annot[i]==null)
208 // ann[i] = new Annotation(annot[i], "", ' ', 0f);
209 // //System.out.print(annot[i]);
212 // AlignmentAnnotation toto = new AlignmentAnnotation("Secondary structure","",ann);
213 // this.annotations.addElement(toto);
215 // Creating empty structure of suitable size
216 // int[] str = new int[seq.size()];
217 // for (int i=0;i<str.length;i++)
219 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
220 // for (int i = 0; i < allbpsTmp.size(); i++) {
221 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
222 // //System.err.println("toto ="+bp);
223 // int bp5 = bp.pos5;
224 // //System.out.println("bp5 ="+bp5);
225 // int bp3 = bp.pos3;
226 //System.out.println("bp3 ="+bp3);
227 //ModeleBP newStyle = bp.createBPStyle(mb, part);
230 //ann = new Annotation(bp5, "", ' ', 0f);
241 public static String print(SequenceI[] s)
243 return "not yet implemented";
246 public String print()
248 System.out.print("affiche :");
249 return print(getSeqsAsArray());
253 * make a friendly ID string.
256 * @return truncated dataName to after last '/'
258 private String safeName(String dataName)
261 while ((b = dataName.indexOf("/")) > -1 && b < dataName.length() )
263 dataName = dataName.substring(b + 1).trim();
266 int e = (dataName.length() - dataName.indexOf("."))+1;
267 dataName = dataName.substring(1,e).trim();