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
96 result = RNAFactory.loadSecStrRNAML(getReader());
98 System.out.println("this is the secondary scructure:" +result.size());
99 //System.out.println("this is the secondary scructure:" +result.toString());
100 //System.out.println("this is the secondary scructure:" +result.size());
101 SequenceI[] seqs = new SequenceI[result.size()];
102 System.out.println(type); //the type is "File"
103 System.out.println(inFile );//inFile is the path
105 for(int i=0;i<result.size();i++)
107 RNA current = result.get(i);
108 System.out.println(current.getSeq());
109 //System.out.println(result.get(i).getStructBPSEQ());
110 System.out.println(result.get(i).getStructDBN(true));
111 System.out.println(i);
112 String rna =current.getStructDBN(true);
113 //System.out.println(result.get(0).getAnnotations());
114 String seq = current.getSeq();
117 int end = seq.length()-1;
119 id = current.getName();
120 seqs[i] = new Sequence(id, seq, begin, end);
121 //System.out.println(seq);
122 System.out.println("Rna is still "+rna);
123 //SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
124 //seqs[i].addSequenceFeature(feat);
126 String[] annot=new String[rna.length()] ;
127 Annotation[] ann = new Annotation[rna.length()];
129 for(int j=0;j<rna.length();j++)
131 annot[j] =rna.substring(j,j+1);
135 for(int k=0;k<rna.length();k++)
137 ann[k] = new Annotation(annot[k], "", jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0), 0f);
140 AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",current.getID(),ann);
142 seqs[i].addAlignmentAnnotation(align);
143 seqs[i].setRNA(result.get(i));
144 this.annotations.addElement(align);
154 public void parse(BufferedReader r) throws ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
156 System.out.println("parse with Buffer (RnamlFile");
157 Hashtable seqhash = new Hashtable();
158 Vector headers = new Vector();
159 //ArrayList<String> seq =new ArrayList();
160 //System.out.println(r);
162 result = RNAFactory.loadSecStr(r,RNAFileType.FILE_TYPE_RNAML);
164 System.out.println("this is the secondary scructure:" +result.toArray());
165 System.out.println("this is the secondary scructure:" +result.toString());
166 System.out.println("this is the secondary scructure:" +result.size());
167 for(int i=0;i<result.size();i++)
169 System.out.println(result.get(0).getSeq());
170 System.out.println(result.get(0).getStructBPSEQ());
171 System.out.println(result.get(0).getStructDBN(true));
172 String rna1 =result.get(0).getStructDBN(true);
173 System.out.println(result.get(0).getAnnotations());
174 String seq = result.get(0).getSeq();
175 System.out.println(type); //the type is "File"
176 System.out.println(inFile );//inFile is the path
178 int end = seq.length()-1;
179 SequenceI[] seqs = new SequenceI[1];
180 id = safeName(getDataName());
181 seqs[0] = new Sequence(id, seq, begin, end);
182 SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
183 seqs[0].addSequenceFeature(feat);
186 String[] annot=new String[10000] ;
187 Annotation[] ann = new Annotation[1000];
188 for(int j=0;j<rna1.length();j++)
190 annot[j] =rna1.substring(j,j+1);
191 //System.out.println(annot[j]);
194 for(int k=0;k<rna1.length();k++)
196 ann[k] = new Annotation(annot[k], "", ' ', 0f);
198 ann[k].secondaryStructure = jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0);
201 AlignmentAnnotation align = new AlignmentAnnotation("Secondary structure","",ann);
202 seqs[0].addAlignmentAnnotation(align);
203 this.annotations.addElement(align);
205 //Annotate3D tintin = new Annotate3D();
207 //System.out.println(tintin);
216 // for(RNAMLParser.RNATmp rnaTmp : RNAMLData.getMolecules())
218 // // Retrieving parsed data
219 // seq = rnaTmp.getSequence(); //contient la séquence sous forme de liste
220 // System.out.println(seq);
221 // String seqAsStr = "";
224 // // Only consider last character, e.g. in case of modified nucleotide
225 // seqAsStr += s.charAt(s.length()-1);
228 // int end = seqAsStr.length()-1;
229 // SequenceI[] seqs = new SequenceI[1];
230 // id = safeName(getDataName());
231 // seqs[0] = new Sequence(id, seqAsStr, begin, end);
232 // SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
234 // seqs[0].addSequenceFeature(feat);
235 // this.setSeqs(seqs);
237 //String pos = annot.substring(1, 2);
238 //System.out.println(annot);
239 //System.out.println(pos);
241 // ann[1] = new Annotation(pos, "", ' ', 0f);
242 // ann[1].secondaryStructure = 'A';
243 //System.out.println(ann[1]);
245 // toto.annotations=ann;
249 //// Annotation[] els = new Annotation[seq.size()];
251 // //System.err.println(""+seq.size());
252 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
253 // String[] annot = new String[10000];
255 // //Annotation[] ann = new Annotation[allbpsTmp.size()];
256 // for (int i = 0; i < allbpsTmp.size(); i++) {
257 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
258 // //System.err.println("toto ="+bp);
259 // int bp5 = bp.pos5;
261 // //annot[bp5]= '(';
262 // System.out.println(annot[bp5]);
263 // //System.out.println("bp5 ="+bp5);
264 // int bp3 = bp.pos3;
267 // System.out.println(annot[bp3]);
268 // //System.out.println(annot.get(bp3));
270 // //String pos1 = annot.substring(bp5, bp5+1);
271 // //String pos2 = annot.substring(bp3, bp3+1);
272 // //ann[i] = new Annotation(pos1, "", ' ', 0f);
273 // //ann[i+1] = new Annotation(pos2, "", ' ', 0f);
274 // //System.out.println(pos1);
276 // //System.out.println("bp3 ="+bp3);
277 // //ModeleBP newStyle = bp.createBPStyle(mb, part);
279 // Annotation[] ann = new Annotation[annot.length+1];
280 // for(int i=0;i<annot.length;i++)
282 // if(annot[i]==null)
287 // ann[i] = new Annotation(annot[i], "", ' ', 0f);
288 // //System.out.print(annot[i]);
291 // AlignmentAnnotation toto = new AlignmentAnnotation("Secondary structure","",ann);
292 // this.annotations.addElement(toto);
294 // Creating empty structure of suitable size
295 // int[] str = new int[seq.size()];
296 // for (int i=0;i<str.length;i++)
298 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
299 // for (int i = 0; i < allbpsTmp.size(); i++) {
300 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
301 // //System.err.println("toto ="+bp);
302 // int bp5 = bp.pos5;
303 // //System.out.println("bp5 ="+bp5);
304 // int bp3 = bp.pos3;
305 //System.out.println("bp3 ="+bp3);
306 //ModeleBP newStyle = bp.createBPStyle(mb, part);
309 //ann = new Annotation(bp5, "", ' ', 0f);
320 public static String print(SequenceI[] s)
322 return "not yet implemented";
325 public String print()
327 System.out.print("affiche :");
328 return print(getSeqsAsArray());
332 * make a friendly ID string.
335 * @return truncated dataName to after last '/'
337 private String safeName(String dataName)
340 while ((b = dataName.indexOf("/")) > -1 && b < dataName.length() )
342 dataName = dataName.substring(b + 1).trim();
345 int e = (dataName.length() - dataName.indexOf("."))+1;
346 dataName = dataName.substring(1,e).trim();
350 public ArrayList getRNA()
355 public Vector getAnnot()