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.Sequence;
23 import jalview.datamodel.SequenceI;
25 import java.io.BufferedReader;
26 import java.io.FileNotFoundException;
27 import java.io.FileReader;
28 import java.io.IOException;
29 import java.util.ArrayList;
31 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
32 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
33 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
34 import fr.orsay.lri.varna.factories.RNAFactory;
35 import fr.orsay.lri.varna.models.rna.RNA;
37 public class RnamlFile extends AlignFile
41 protected ArrayList<RNA> result;
49 public RnamlFile(String inFile, String type) throws IOException
55 public RnamlFile(FileParse source) throws IOException
61 // public RnamlFile(BufferedReader r) throws IOException,
62 // ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException,
63 // ExceptionPermissionDenied, ExceptionLoadingFailed
67 // // sets the index of each sequence in the alignment
68 // for( int i=0,c=seqs.size(); i<c; i++ ) {
69 // seqs.get(i).setIndex(i);
75 public BufferedReader CreateReader() throws FileNotFoundException
78 fr = new FileReader(inFile);
80 BufferedReader r = new BufferedReader(fr);
84 public void parse() throws IOException
86 if (System.getProperty("java.version").indexOf("1.6")>-1 || System.getProperty("java.version").indexOf("1.5")>-1)
88 // patch for 'This parser does not support specification "null" version "null"' error
89 // this hack ensures we get a properly updated SAXParserFactory on older JVMs
90 // thanks to Stefan Birkner over at https://coderwall.com/p/kqsrrw
91 System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
96 result = RNAFactory.loadSecStrRNAML(getReader());
98 } catch (ExceptionPermissionDenied pdx)
100 errormessage = "Couldn't access datasource (" + pdx.getMessage()
102 throw new IOException(pdx);
103 } catch (ExceptionLoadingFailed lf)
105 errormessage = "Couldn't process data as RNAML file ("
106 + lf.getMessage() + ")";
107 throw new IOException(lf);
108 } catch (ExceptionFileFormatOrSyntax iff)
110 errormessage = "Invalid RNAML file (" + iff.getMessage() + ")";
111 throw new IOException(iff);
114 SequenceI[] seqs = new SequenceI[result.size()];
116 for (int i = 0; i < result.size(); i++)
118 // DEBUG System.err.println("RNAML entry "+i);
119 RNA current = result.get(i);
120 String seq = current.getSeq();
121 // DEBUG System.err.println(seq);
122 String rna = current.getStructDBN(true);
123 // DEBUG System.err.println(rna);
126 int end = seq.length(); // TODO: compute non-gapped length for sequence
128 id = current.getName();
129 seqs[i] = new Sequence(id, seq, begin, end);
131 String[] annot = new String[rna.length()];
132 Annotation[] ann = new Annotation[rna.length()];
134 for (int j = 0; j < rna.length(); j++)
136 annot[j] = rna.substring(j, j + 1);
140 for (int k = 0; k < rna.length(); k++)
142 ann[k] = new Annotation(annot[k], "",
143 jalview.schemes.ResidueProperties.getRNASecStrucState(
144 annot[k]).charAt(0), 0f);
147 AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",
148 current.getID(), ann);
150 seqs[i].addAlignmentAnnotation(align);
151 seqs[i].setRNA(result.get(i));
152 annotations.addElement(align);
157 public static String print(SequenceI[] s)
159 // TODO: implement RNAML export option
160 return "not yet implemented";
163 public String print()
165 return print(getSeqsAsArray());
169 * make a friendly ID string.
172 * @return truncated dataName to after last '/'
174 private String safeName(String dataName)
177 while ((b = dataName.indexOf("/")) > -1 && b < dataName.length())
179 dataName = dataName.substring(b + 1).trim();
182 int e = (dataName.length() - dataName.indexOf(".")) + 1;
183 dataName = dataName.substring(1, e).trim();