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
89 result = RNAFactory.loadSecStrRNAML(getReader());
91 } catch (ExceptionPermissionDenied pdx)
93 errormessage = "Couldn't access datasource (" + pdx.getMessage()
95 throw new IOException(pdx);
96 } catch (ExceptionLoadingFailed lf)
98 errormessage = "Couldn't process data as RNAML file ("
99 + lf.getMessage() + ")";
100 throw new IOException(lf);
101 } catch (ExceptionFileFormatOrSyntax iff)
103 errormessage = "Invalid RNAML file (" + iff.getMessage() + ")";
104 throw new IOException(iff);
107 SequenceI[] seqs = new SequenceI[result.size()];
109 for (int i = 0; i < result.size(); i++)
111 // DEBUG System.err.println("RNAML entry "+i);
112 RNA current = result.get(i);
113 String seq = current.getSeq();
114 // DEBUG System.err.println(seq);
115 String rna = current.getStructDBN(true);
116 // DEBUG System.err.println(rna);
119 int end = seq.length(); // TODO: compute non-gapped length for sequence
121 id = current.getName();
122 seqs[i] = new Sequence(id, seq, begin, end);
124 String[] annot = new String[rna.length()];
125 Annotation[] ann = new Annotation[rna.length()];
127 for (int j = 0; j < rna.length(); j++)
129 annot[j] = rna.substring(j, j + 1);
133 for (int k = 0; k < rna.length(); k++)
135 ann[k] = new Annotation(annot[k], "",
136 jalview.schemes.ResidueProperties.getRNASecStrucState(
137 annot[k]).charAt(0), 0f);
140 AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",
141 current.getID(), ann);
143 seqs[i].addAlignmentAnnotation(align);
144 seqs[i].setRNA(result.get(i));
145 annotations.addElement(align);
150 public static String print(SequenceI[] s)
152 // TODO: implement RNAML export option
153 return "not yet implemented";
156 public String print()
158 return print(getSeqsAsArray());
162 * make a friendly ID string.
165 * @return truncated dataName to after last '/'
167 private String safeName(String dataName)
170 while ((b = dataName.indexOf("/")) > -1 && b < dataName.length())
172 dataName = dataName.substring(b + 1).trim();
175 int e = (dataName.length() - dataName.indexOf(".")) + 1;
176 dataName = dataName.substring(1, e).trim();