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.factories.RNAFactory;
40 import fr.orsay.lri.varna.factories.RNAFactory.RNAFileType;
41 import fr.orsay.lri.varna.models.rna.RNA;
42 import fr.orsay.lri.varna.utils.RNAMLParser;
47 public class RnamlFile extends AlignFile
50 protected ArrayList<RNA> result;
58 public RnamlFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException
64 public RnamlFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException
70 // public RnamlFile(BufferedReader r) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
74 // // sets the index of each sequence in the alignment
75 // for( int i=0,c=seqs.size(); i<c; i++ ) {
76 // seqs.get(i).setIndex(i);
82 public BufferedReader CreateReader() throws FileNotFoundException
85 fr = new FileReader(inFile);
87 BufferedReader r = new BufferedReader (fr);
92 public void parse() throws FileNotFoundException, ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
95 fr = new FileReader(inFile);
97 BufferedReader r = new BufferedReader (fr);
98 Hashtable seqhash = new Hashtable();
99 Vector headers = new Vector();
100 //ArrayList<String> seq =new ArrayList();
101 //System.out.println(r);
104 result = RNAFactory.loadSecStrRNAML(r);
106 System.out.println("this is the secondary scructure:" +result.toArray());
107 //System.out.println("this is the secondary scructure:" +result.toString());
108 //System.out.println("this is the secondary scructure:" +result.size());
109 for(int i=0;i<result.size();i++)
111 //System.out.println(result.get(0).getSeq());
112 //System.out.println(result.get(0).getStructBPSEQ());
113 //System.out.println(result.get(0).getStructDBN(true));
114 String rna1 =result.get(0).getStructDBN(true);
115 //System.out.println(result.get(0).getAnnotations());
116 String seq = result.get(0).getSeq();
117 System.out.println(type); //the type is "File"
118 System.out.println(inFile );//inFile is the path
120 int end = seq.length()-1;
121 SequenceI[] seqs = new SequenceI[1];
122 id = safeName(getDataName());
123 seqs[0] = new Sequence(id, seq, begin, end);
124 SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
125 seqs[0].addSequenceFeature(feat);
128 String[] annot=new String[10000] ;
129 Annotation[] ann = new Annotation[1000];
130 for(int j=0;j<rna1.length();j++)
132 annot[j] =rna1.substring(j,j+1);
133 System.out.println(annot[j]);
136 for(int k=0;k<rna1.length();k++)
138 ann[k] = new Annotation(annot[k], "", ' ', 0f);
140 ann[k].secondaryStructure = jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0);
143 AlignmentAnnotation align = new AlignmentAnnotation("Secondary structure","",ann);
144 seqs[0].addAlignmentAnnotation(align);
145 seqs[0].setRNA(result.get(begin));
146 this.annotations.addElement(align);
151 //Annotate3D tintin = new Annotate3D();
153 //System.out.println(tintin);
157 public void parse(BufferedReader r) throws ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
159 System.out.println("parse with Buffer (RnamlFile");
160 Hashtable seqhash = new Hashtable();
161 Vector headers = new Vector();
162 //ArrayList<String> seq =new ArrayList();
163 //System.out.println(r);
165 result = RNAFactory.loadSecStr(r,RNAFileType.FILE_TYPE_RNAML);
167 System.out.println("this is the secondary scructure:" +result.toArray());
168 System.out.println("this is the secondary scructure:" +result.toString());
169 System.out.println("this is the secondary scructure:" +result.size());
170 for(int i=0;i<result.size();i++)
172 System.out.println(result.get(0).getSeq());
173 System.out.println(result.get(0).getStructBPSEQ());
174 System.out.println(result.get(0).getStructDBN(true));
175 String rna1 =result.get(0).getStructDBN(true);
176 System.out.println(result.get(0).getAnnotations());
177 String seq = result.get(0).getSeq();
178 System.out.println(type); //the type is "File"
179 System.out.println(inFile );//inFile is the path
181 int end = seq.length()-1;
182 SequenceI[] seqs = new SequenceI[1];
183 id = safeName(getDataName());
184 seqs[0] = new Sequence(id, seq, begin, end);
185 SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
186 seqs[0].addSequenceFeature(feat);
189 String[] annot=new String[10000] ;
190 Annotation[] ann = new Annotation[1000];
191 for(int j=0;j<rna1.length();j++)
193 annot[j] =rna1.substring(j,j+1);
194 //System.out.println(annot[j]);
197 for(int k=0;k<rna1.length();k++)
199 ann[k] = new Annotation(annot[k], "", ' ', 0f);
201 ann[k].secondaryStructure = jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0);
204 AlignmentAnnotation align = new AlignmentAnnotation("Secondary structure","",ann);
205 seqs[0].addAlignmentAnnotation(align);
206 this.annotations.addElement(align);
208 //Annotate3D tintin = new Annotate3D();
210 //System.out.println(tintin);
219 // for(RNAMLParser.RNATmp rnaTmp : RNAMLData.getMolecules())
221 // // Retrieving parsed data
222 // seq = rnaTmp.getSequence(); //contient la séquence sous forme de liste
223 // System.out.println(seq);
224 // String seqAsStr = "";
227 // // Only consider last character, e.g. in case of modified nucleotide
228 // seqAsStr += s.charAt(s.length()-1);
231 // int end = seqAsStr.length()-1;
232 // SequenceI[] seqs = new SequenceI[1];
233 // id = safeName(getDataName());
234 // seqs[0] = new Sequence(id, seqAsStr, begin, end);
235 // SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
237 // seqs[0].addSequenceFeature(feat);
238 // this.setSeqs(seqs);
240 //String pos = annot.substring(1, 2);
241 //System.out.println(annot);
242 //System.out.println(pos);
244 // ann[1] = new Annotation(pos, "", ' ', 0f);
245 // ann[1].secondaryStructure = 'A';
246 //System.out.println(ann[1]);
248 // toto.annotations=ann;
252 //// Annotation[] els = new Annotation[seq.size()];
254 // //System.err.println(""+seq.size());
255 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
256 // String[] annot = new String[10000];
258 // //Annotation[] ann = new Annotation[allbpsTmp.size()];
259 // for (int i = 0; i < allbpsTmp.size(); i++) {
260 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
261 // //System.err.println("toto ="+bp);
262 // int bp5 = bp.pos5;
264 // //annot[bp5]= '(';
265 // System.out.println(annot[bp5]);
266 // //System.out.println("bp5 ="+bp5);
267 // int bp3 = bp.pos3;
270 // System.out.println(annot[bp3]);
271 // //System.out.println(annot.get(bp3));
273 // //String pos1 = annot.substring(bp5, bp5+1);
274 // //String pos2 = annot.substring(bp3, bp3+1);
275 // //ann[i] = new Annotation(pos1, "", ' ', 0f);
276 // //ann[i+1] = new Annotation(pos2, "", ' ', 0f);
277 // //System.out.println(pos1);
279 // //System.out.println("bp3 ="+bp3);
280 // //ModeleBP newStyle = bp.createBPStyle(mb, part);
282 // Annotation[] ann = new Annotation[annot.length+1];
283 // for(int i=0;i<annot.length;i++)
285 // if(annot[i]==null)
290 // ann[i] = new Annotation(annot[i], "", ' ', 0f);
291 // //System.out.print(annot[i]);
294 // AlignmentAnnotation toto = new AlignmentAnnotation("Secondary structure","",ann);
295 // this.annotations.addElement(toto);
297 // Creating empty structure of suitable size
298 // int[] str = new int[seq.size()];
299 // for (int i=0;i<str.length;i++)
301 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
302 // for (int i = 0; i < allbpsTmp.size(); i++) {
303 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
304 // //System.err.println("toto ="+bp);
305 // int bp5 = bp.pos5;
306 // //System.out.println("bp5 ="+bp5);
307 // int bp3 = bp.pos3;
308 //System.out.println("bp3 ="+bp3);
309 //ModeleBP newStyle = bp.createBPStyle(mb, part);
312 //ann = new Annotation(bp5, "", ' ', 0f);
323 public static String print(SequenceI[] s)
325 return "not yet implemented";
328 public String print()
330 System.out.print("affiche :");
331 return print(getSeqsAsArray());
335 * make a friendly ID string.
338 * @return truncated dataName to after last '/'
340 private String safeName(String dataName)
343 while ((b = dataName.indexOf("/")) > -1 && b < dataName.length() )
345 dataName = dataName.substring(b + 1).trim();
348 int e = (dataName.length() - dataName.indexOf("."))+1;
349 dataName = dataName.substring(1,e).trim();
353 public ArrayList getRNA()
358 public Vector getAnnot()