2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
20 import jalview.datamodel.AlignmentAnnotation;
21 import jalview.datamodel.Annotation;
22 import jalview.datamodel.SecondaryStructureAnnotation;
23 import jalview.datamodel.Sequence;
24 import jalview.datamodel.SequenceFeature;
25 import jalview.datamodel.SequenceI;
26 import jalview.ws.jws1.Annotate3D;
28 import java.io.BufferedReader;
29 import java.io.FileNotFoundException;
30 import java.io.IOException;
31 import java.io.Reader;
32 import java.io.FileReader;
33 import java.lang.reflect.Array;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.Hashtable;
37 import java.util.List;
38 import java.util.Vector;
40 import javax.xml.parsers.ParserConfigurationException;
41 import javax.xml.parsers.SAXParser;
42 import javax.xml.parsers.SAXParserFactory;
44 import org.xml.sax.InputSource;
45 import org.xml.sax.SAXException;
47 import com.stevesoft.pat.Regex;
49 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
50 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
51 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
52 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
53 import fr.orsay.lri.varna.factories.RNAFactory;
54 import fr.orsay.lri.varna.factories.RNAFactory.RNAFileType;
55 import fr.orsay.lri.varna.models.rna.RNA;
56 import fr.orsay.lri.varna.utils.RNAMLParser;
61 public class RnamlFile extends AlignFile
64 protected ArrayList<RNA> result;
72 public RnamlFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
78 public RnamlFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed, InterruptedException, ExceptionUnmatchedClosingParentheses
84 // public RnamlFile(BufferedReader r) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
88 // // sets the index of each sequence in the alignment
89 // for( int i=0,c=seqs.size(); i<c; i++ ) {
90 // seqs.get(i).setIndex(i);
96 public BufferedReader CreateReader() throws FileNotFoundException
99 fr = new FileReader(inFile);
101 BufferedReader r = new BufferedReader (fr);
106 @SuppressWarnings("unchecked")
107 public void parse() throws FileNotFoundException, ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
109 result = RNAFactory.loadSecStrRNAML(getReader());
111 System.out.println("this is the secondary scructure:" +result.size());
112 //System.out.println("this is the secondary scructure:" +result.toString());
113 //System.out.println("this is the secondary scructure:" +result.size());
114 SequenceI[] seqs = new SequenceI[result.size()];
115 System.out.println(type); //the type is "File"
116 System.out.println(inFile );//inFile is the path
118 for(int i=0;i<result.size();i++)
120 RNA current = result.get(i);
121 System.out.println(current.getSeq());
122 //System.out.println(result.get(i).getStructBPSEQ());
123 System.out.println(result.get(i).getStructDBN(true));
124 System.out.println(i);
125 String rna =current.getStructDBN(true);
126 //System.out.println(result.get(0).getAnnotations());
127 String seq = current.getSeq();
130 int end = seq.length();
132 id = current.getName();
133 seqs[i] = new Sequence(id, seq, begin, end);
134 //System.out.println(seq);
135 System.out.println("Rna is still "+rna);
136 //SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
137 //seqs[i].addSequenceFeature(feat);
139 String[] annot=new String[rna.length()] ;
140 Annotation[] ann = new Annotation[rna.length()];
142 for(int j=0;j<rna.length();j++)
144 annot[j] =rna.substring(j,j+1);
148 for(int k=0;k<rna.length();k++)
150 ann[k] = new Annotation(annot[k], "", jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0), 0f);
153 AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",current.getID(),ann);
155 seqs[i].addAlignmentAnnotation(align);
156 seqs[i].setRNA(result.get(i));
157 this.annotations.addElement(align);
167 public void parse(BufferedReader r) throws ExceptionPermissionDenied, ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
169 System.out.println("parse with Buffer (RnamlFile");
170 Hashtable seqhash = new Hashtable();
171 Vector headers = new Vector();
172 //ArrayList<String> seq =new ArrayList();
173 //System.out.println(r);
175 result = RNAFactory.loadSecStr(r,RNAFileType.FILE_TYPE_RNAML);
177 System.out.println("this is the secondary scructure:" +result.toArray());
178 System.out.println("this is the secondary scructure:" +result.toString());
179 System.out.println("this is the secondary scructure:" +result.size());
180 for(int i=0;i<result.size();i++)
182 System.out.println(result.get(0).getSeq());
183 System.out.println(result.get(0).getStructBPSEQ());
184 System.out.println(result.get(0).getStructDBN(true));
185 String rna1 =result.get(0).getStructDBN(true);
186 System.out.println(result.get(0).getAnnotations());
187 String seq = result.get(0).getSeq();
188 System.out.println(type); //the type is "File"
189 System.out.println(inFile );//inFile is the path
191 int end = seq.length()-1;
192 SequenceI[] seqs = new SequenceI[1];
193 id = safeName(getDataName());
194 seqs[0] = new Sequence(id, seq, begin, end);
195 SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
196 seqs[0].addSequenceFeature(feat);
199 String[] annot=new String[10000] ;
200 Annotation[] ann = new Annotation[1000];
201 for(int j=0;j<rna1.length();j++)
203 annot[j] =rna1.substring(j,j+1);
204 //System.out.println(annot[j]);
207 for(int k=0;k<rna1.length();k++)
209 ann[k] = new Annotation(annot[k], "", ' ', 0f);
211 ann[k].secondaryStructure = jalview.schemes.ResidueProperties.getRNASecStrucState(annot[k]).charAt(0);
214 AlignmentAnnotation align = new AlignmentAnnotation("Secondary structure","",ann);
215 seqs[0].addAlignmentAnnotation(align);
216 this.annotations.addElement(align);
218 //Annotate3D tintin = new Annotate3D();
220 //System.out.println(tintin);
229 // for(RNAMLParser.RNATmp rnaTmp : RNAMLData.getMolecules())
231 // // Retrieving parsed data
232 // seq = rnaTmp.getSequence(); //contient la séquence sous forme de liste
233 // System.out.println(seq);
234 // String seqAsStr = "";
237 // // Only consider last character, e.g. in case of modified nucleotide
238 // seqAsStr += s.charAt(s.length()-1);
241 // int end = seqAsStr.length()-1;
242 // SequenceI[] seqs = new SequenceI[1];
243 // id = safeName(getDataName());
244 // seqs[0] = new Sequence(id, seqAsStr, begin, end);
245 // SequenceFeature feat = new SequenceFeature(type, "",5, 13, 0f, null);
247 // seqs[0].addSequenceFeature(feat);
248 // this.setSeqs(seqs);
250 //String pos = annot.substring(1, 2);
251 //System.out.println(annot);
252 //System.out.println(pos);
254 // ann[1] = new Annotation(pos, "", ' ', 0f);
255 // ann[1].secondaryStructure = 'A';
256 //System.out.println(ann[1]);
258 // toto.annotations=ann;
262 //// Annotation[] els = new Annotation[seq.size()];
264 // //System.err.println(""+seq.size());
265 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
266 // String[] annot = new String[10000];
268 // //Annotation[] ann = new Annotation[allbpsTmp.size()];
269 // for (int i = 0; i < allbpsTmp.size(); i++) {
270 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
271 // //System.err.println("toto ="+bp);
272 // int bp5 = bp.pos5;
274 // //annot[bp5]= '(';
275 // System.out.println(annot[bp5]);
276 // //System.out.println("bp5 ="+bp5);
277 // int bp3 = bp.pos3;
280 // System.out.println(annot[bp3]);
281 // //System.out.println(annot.get(bp3));
283 // //String pos1 = annot.substring(bp5, bp5+1);
284 // //String pos2 = annot.substring(bp3, bp3+1);
285 // //ann[i] = new Annotation(pos1, "", ' ', 0f);
286 // //ann[i+1] = new Annotation(pos2, "", ' ', 0f);
287 // //System.out.println(pos1);
289 // //System.out.println("bp3 ="+bp3);
290 // //ModeleBP newStyle = bp.createBPStyle(mb, part);
292 // Annotation[] ann = new Annotation[annot.length+1];
293 // for(int i=0;i<annot.length;i++)
295 // if(annot[i]==null)
300 // ann[i] = new Annotation(annot[i], "", ' ', 0f);
301 // //System.out.print(annot[i]);
304 // AlignmentAnnotation toto = new AlignmentAnnotation("Secondary structure","",ann);
305 // this.annotations.addElement(toto);
307 // Creating empty structure of suitable size
308 // int[] str = new int[seq.size()];
309 // for (int i=0;i<str.length;i++)
311 // Vector<RNAMLParser.BPTemp> allbpsTmp = rnaTmp.getStructure();
312 // for (int i = 0; i < allbpsTmp.size(); i++) {
313 // RNAMLParser.BPTemp bp = allbpsTmp.get(i);
314 // //System.err.println("toto ="+bp);
315 // int bp5 = bp.pos5;
316 // //System.out.println("bp5 ="+bp5);
317 // int bp3 = bp.pos3;
318 //System.out.println("bp3 ="+bp3);
319 //ModeleBP newStyle = bp.createBPStyle(mb, part);
322 //ann = new Annotation(bp5, "", ' ', 0f);
333 public static String print(SequenceI[] s)
335 return "not yet implemented";
338 public String print()
340 System.out.print("affiche :");
341 return print(getSeqsAsArray());
345 * make a friendly ID string.
348 * @return truncated dataName to after last '/'
350 private String safeName(String dataName)
353 while ((b = dataName.indexOf("/")) > -1 && b < dataName.length() )
355 dataName = dataName.substring(b + 1).trim();
358 int e = (dataName.length() - dataName.indexOf("."))+1;
359 dataName = dataName.substring(1,e).trim();
363 public ArrayList getRNA()
368 public Vector getAnnot()