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;
13 import jalview.ws.jws1.Annotate3D;
15 import java.io.BufferedReader;
16 import java.io.FileNotFoundException;
17 import java.io.IOException;
18 import java.io.Reader;
19 import java.io.FileReader;
20 import java.lang.reflect.Array;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.Hashtable;
24 import java.util.List;
25 import java.util.Vector;
27 import javax.xml.parsers.ParserConfigurationException;
28 import javax.xml.parsers.SAXParser;
29 import javax.xml.parsers.SAXParserFactory;
31 import org.xml.sax.InputSource;
32 import org.xml.sax.SAXException;
34 import com.stevesoft.pat.Regex;
36 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
37 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
38 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
39 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
40 import fr.orsay.lri.varna.factories.RNAFactory;
41 import fr.orsay.lri.varna.factories.RNAFactory.RNAFileType;
42 import fr.orsay.lri.varna.models.rna.RNA;
43 import fr.orsay.lri.varna.utils.RNAMLParser;
48 public class RnamlFile extends AlignFile
51 protected ArrayList<RNA> result;
59 public RnamlFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
65 public RnamlFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
71 // public RnamlFile(BufferedReader r) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
75 // // sets the index of each sequence in the alignment
76 // for( int i=0,c=seqs.size(); i<c; i++ ) {
77 // seqs.get(i).setIndex(i);
83 public BufferedReader CreateReader() throws FileNotFoundException
86 fr = new FileReader(inFile);
88 BufferedReader r = new BufferedReader (fr);
93 @SuppressWarnings("unchecked")
94 public void parse() throws FileNotFoundException, ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
97 fr = new FileReader(inFile);
99 BufferedReader r = new BufferedReader (fr);
101 //ArrayList<String> seq =new ArrayList();
102 //System.out.println(r);
105 result = RNAFactory.loadSecStrRNAML(r);
107 System.out.println("this is the secondary scructure:" +result.size());
108 //System.out.println("this is the secondary scructure:" +result.toString());
109 //System.out.println("this is the secondary scructure:" +result.size());
110 SequenceI[] seqs = new SequenceI[result.size()];
111 System.out.println(type); //the type is "File"
112 System.out.println(inFile );//inFile is the path
114 for(int i=0;i<result.size();i++)
116 RNA current = result.get(i);
117 System.out.println(current.getSeq());
118 //System.out.println(result.get(i).getStructBPSEQ());
119 System.out.println(result.get(i).getStructDBN(true));
120 System.out.println(i);
121 String rna =current.getStructDBN(true);
122 //System.out.println(result.get(0).getAnnotations());
123 String seq = current.getSeq();
126 int end = seq.length()-1;
128 id = safeName(getDataName());
129 seqs[i] = new Sequence(id, seq, begin, end);
130 //System.out.println(seq);
131 System.out.println("Rna is still "+rna);
132 //SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
133 //seqs[i].addSequenceFeature(feat);
135 String[] annot=new String[rna.length()] ;
136 Annotation[] ann = new Annotation[rna.length()];
138 for(int j=0;j<rna.length();j++)
140 annot[j] =rna.substring(j,j+1);
144 for(int k=0;k<rna.length();k++)
146 ann[k] = new Annotation(annot[k], "", jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0), 0f);
149 AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",current.getID(),ann);
151 seqs[i].addAlignmentAnnotation(align);
152 seqs[i].setRNA(result.get(i));
153 this.annotations.addElement(align);
163 public void parse(BufferedReader r) throws ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
165 System.out.println("parse with Buffer (RnamlFile");
166 Hashtable seqhash = new Hashtable();
167 Vector headers = new Vector();
168 //ArrayList<String> seq =new ArrayList();
169 //System.out.println(r);
171 result = RNAFactory.loadSecStr(r,RNAFileType.FILE_TYPE_RNAML);
173 System.out.println("this is the secondary scructure:" +result.toArray());
174 System.out.println("this is the secondary scructure:" +result.toString());
175 System.out.println("this is the secondary scructure:" +result.size());
176 for(int i=0;i<result.size();i++)
178 System.out.println(result.get(0).getSeq());
179 System.out.println(result.get(0).getStructBPSEQ());
180 System.out.println(result.get(0).getStructDBN(true));
181 String rna1 =result.get(0).getStructDBN(true);
182 System.out.println(result.get(0).getAnnotations());
183 String seq = result.get(0).getSeq();
184 System.out.println(type); //the type is "File"
185 System.out.println(inFile );//inFile is the path
187 int end = seq.length()-1;
188 SequenceI[] seqs = new SequenceI[1];
189 id = safeName(getDataName());
190 seqs[0] = new Sequence(id, seq, begin, end);
191 SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
192 seqs[0].addSequenceFeature(feat);
195 String[] annot=new String[10000] ;
196 Annotation[] ann = new Annotation[1000];
197 for(int j=0;j<rna1.length();j++)
199 annot[j] =rna1.substring(j,j+1);
200 //System.out.println(annot[j]);
203 for(int k=0;k<rna1.length();k++)
205 ann[k] = new Annotation(annot[k], "", ' ', 0f);
207 ann[k].secondaryStructure = jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0);
210 AlignmentAnnotation align = new AlignmentAnnotation("Secondary structure","",ann);
211 seqs[0].addAlignmentAnnotation(align);
212 this.annotations.addElement(align);
214 //Annotate3D tintin = new Annotate3D();
216 //System.out.println(tintin);
225 // for(RNAMLParser.RNATmp rnaTmp : RNAMLData.getMolecules())
227 // // Retrieving parsed data
228 // seq = rnaTmp.getSequence(); //contient la séquence sous forme de liste
229 // System.out.println(seq);
230 // String seqAsStr = "";
233 // // Only consider last character, e.g. in case of modified nucleotide
234 // seqAsStr += s.charAt(s.length()-1);
237 // int end = seqAsStr.length()-1;
238 // SequenceI[] seqs = new SequenceI[1];
239 // id = safeName(getDataName());
240 // seqs[0] = new Sequence(id, seqAsStr, begin, end);
241 // SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
243 // seqs[0].addSequenceFeature(feat);
244 // this.setSeqs(seqs);
246 //String pos = annot.substring(1, 2);
247 //System.out.println(annot);
248 //System.out.println(pos);
250 // ann[1] = new Annotation(pos, "", ' ', 0f);
251 // ann[1].secondaryStructure = 'A';
252 //System.out.println(ann[1]);
254 // toto.annotations=ann;
258 //// Annotation[] els = new Annotation[seq.size()];
260 // //System.err.println(""+seq.size());
261 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
262 // String[] annot = new String[10000];
264 // //Annotation[] ann = new Annotation[allbpsTmp.size()];
265 // for (int i = 0; i < allbpsTmp.size(); i++) {
266 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
267 // //System.err.println("toto ="+bp);
268 // int bp5 = bp.pos5;
270 // //annot[bp5]= '(';
271 // System.out.println(annot[bp5]);
272 // //System.out.println("bp5 ="+bp5);
273 // int bp3 = bp.pos3;
276 // System.out.println(annot[bp3]);
277 // //System.out.println(annot.get(bp3));
279 // //String pos1 = annot.substring(bp5, bp5+1);
280 // //String pos2 = annot.substring(bp3, bp3+1);
281 // //ann[i] = new Annotation(pos1, "", ' ', 0f);
282 // //ann[i+1] = new Annotation(pos2, "", ' ', 0f);
283 // //System.out.println(pos1);
285 // //System.out.println("bp3 ="+bp3);
286 // //ModeleBP newStyle = bp.createBPStyle(mb, part);
288 // Annotation[] ann = new Annotation[annot.length+1];
289 // for(int i=0;i<annot.length;i++)
291 // if(annot[i]==null)
296 // ann[i] = new Annotation(annot[i], "", ' ', 0f);
297 // //System.out.print(annot[i]);
300 // AlignmentAnnotation toto = new AlignmentAnnotation("Secondary structure","",ann);
301 // this.annotations.addElement(toto);
303 // Creating empty structure of suitable size
304 // int[] str = new int[seq.size()];
305 // for (int i=0;i<str.length;i++)
307 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
308 // for (int i = 0; i < allbpsTmp.size(); i++) {
309 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
310 // //System.err.println("toto ="+bp);
311 // int bp5 = bp.pos5;
312 // //System.out.println("bp5 ="+bp5);
313 // int bp3 = bp.pos3;
314 //System.out.println("bp3 ="+bp3);
315 //ModeleBP newStyle = bp.createBPStyle(mb, part);
318 //ann = new Annotation(bp5, "", ' ', 0f);
329 public static String print(SequenceI[] s)
331 return "not yet implemented";
334 public String print()
336 System.out.print("affiche :");
337 return print(getSeqsAsArray());
341 * make a friendly ID string.
344 * @return truncated dataName to after last '/'
346 private String safeName(String dataName)
349 while ((b = dataName.indexOf("/")) > -1 && b < dataName.length() )
351 dataName = dataName.substring(b + 1).trim();
354 int e = (dataName.length() - dataName.indexOf("."))+1;
355 dataName = dataName.substring(1,e).trim();
359 public ArrayList getRNA()
364 public Vector getAnnot()