Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.io

File RnamlFile.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
0% of files have more coverage

Code metrics

20
59
9
1
241
159
25
0.42
6.56
9
2.78

Classes

Class Line # Actions
RnamlFile 45 59 25
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.io;
22   
23    import jalview.analysis.Rna;
24    import jalview.datamodel.AlignmentAnnotation;
25    import jalview.datamodel.Annotation;
26    import jalview.datamodel.Sequence;
27    import jalview.datamodel.SequenceI;
28    import jalview.util.MessageManager;
29   
30    import java.io.BufferedReader;
31    import java.io.FileNotFoundException;
32    import java.io.FileReader;
33    import java.io.IOException;
34    import java.util.ArrayList;
35    import java.util.List;
36   
37    import com.stevesoft.pat.Regex;
38   
39    import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
40    import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
41    import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
42    import fr.orsay.lri.varna.factories.RNAFactory;
43    import fr.orsay.lri.varna.models.rna.RNA;
44   
 
45    public class RnamlFile extends AlignFile
46    {
47    public String id;
48   
49    protected ArrayList<RNA> result;
50   
 
51  0 toggle public RnamlFile()
52    {
53  0 super();
54   
55    }
56   
 
57  0 toggle public RnamlFile(String inFile, DataSourceType type) throws IOException
58    {
59  0 super(inFile, type);
60   
61    }
62   
 
63  0 toggle public RnamlFile(FileParse source) throws IOException
64    {
65  0 super(source);
66   
67    }
68   
 
69  0 toggle public BufferedReader CreateReader() throws FileNotFoundException
70    {
71  0 FileReader fr = null;
72  0 fr = new FileReader(inFile);
73   
74  0 BufferedReader r = new BufferedReader(fr);
75  0 return r;
76    }
77   
78    /*
79    * (non-Javadoc)
80    *
81    * @see jalview.io.AlignFile#parse()
82    */
 
83  0 toggle @Override
84    public void parse() throws IOException
85    {
86  0 if (System.getProperty("java.version").indexOf("1.6") > -1
87    || System.getProperty("java.version").indexOf("1.5") > -1)
88    {
89    // patch for 'This parser does not support specification "null" version
90    // "null"' error
91    // this hack ensures we get a properly updated SAXParserFactory on older
92    // JVMs
93    // thanks to Stefan Birkner over at https://coderwall.com/p/kqsrrw
94  0 System.setProperty("javax.xml.parsers.SAXParserFactory",
95    "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
96    }
97    // rather than lose exception semantics whilst parsing RNAML with VARNA we
98    // wrap the routine and catch all exceptions before passing them up the
99    // chain as an IOException
100  0 try
101    {
102  0 _parse();
103    } catch (ExceptionPermissionDenied pdx)
104    {
105  0 errormessage = MessageManager.formatMessage(
106    "exception.rnaml_couldnt_access_datasource", new String[]
107    { pdx.getMessage() });
108  0 throw new IOException(pdx);
109    } catch (ExceptionLoadingFailed lf)
110    {
111  0 errormessage = MessageManager.formatMessage(
112    "exception.ranml_couldnt_process_data", new String[]
113    { lf.getMessage() });
114  0 throw new IOException(lf);
115    } catch (ExceptionFileFormatOrSyntax iff)
116    {
117  0 errormessage = MessageManager
118    .formatMessage("exception.ranml_invalid_file", new String[]
119    { iff.getMessage() });
120  0 throw new IOException(iff);
121    } catch (Exception x)
122    {
123  0 error = true;
124  0 errormessage = MessageManager.formatMessage(
125    "exception.ranml_problem_parsing_data", new String[]
126    { x.getMessage() });
127  0 throw new IOException(errormessage, x);
128    }
129    }
130   
 
131  0 toggle @SuppressWarnings("unchecked")
132    public void _parse()
133    throws FileNotFoundException, ExceptionPermissionDenied,
134    ExceptionLoadingFailed, ExceptionFileFormatOrSyntax
135    {
136   
137  0 result = RNAFactory.loadSecStrRNAML(getReader());
138   
139    // ArrayList<ArrayList> allarray = new ArrayList();
140    // ArrayList<ArrayList<SimpleBP>> BP = new ArrayList();
141    // ArrayList strucinarray = new ArrayList();
142  0 SequenceI[] sqs = new SequenceI[result.size()];
143   
144  0 for (int i = 0; i < result.size(); i++)
145    {
146   
147  0 RNA current = result.get(i);
148  0 String rna = current.getStructDBN(true);
149  0 String seq = current.getSeq();
150  0 int begin = 1;
151  0 int end = seq.length();
152   
153  0 id = current.getName();
154  0 if (id == null || id.trim().length() == 0)
155    {
156  0 id = safeName(getDataName());
157  0 if (result.size() > 1)
158    {
159  0 id += "." + i;
160    }
161    }
162  0 sqs[i] = new Sequence(id, seq, begin, end);
163  0 if (seq.length() != (end - begin + 1))
164    {
165  0 sqs[i].setEnd(sqs[i].findPosition(sqs[i].getLength()));
166    }
167  0 String[] annot = new String[rna.length()];
168  0 Annotation[] ann = new Annotation[rna.length()];
169   
170  0 for (int j = 0; j < rna.length(); j++)
171    {
172  0 annot[j] = "" + rna.charAt(j);
173   
174    }
175  0 for (int k = 0; k < rna.length(); k++)
176    {
177  0 ann[k] = new Annotation(annot[k], "",
178    Rna.getRNASecStrucState(annot[k]).charAt(0), 0f);
179    }
180   
181  0 AlignmentAnnotation align = new AlignmentAnnotation(
182    "Secondary Structure",
183  0 current.getID().trim().length() > 0
184    ? "Secondary Structure for " + current.getID()
185    : "",
186    ann);
187   
188  0 sqs[i].addAlignmentAnnotation(align);
189  0 sqs[i].setRNA(result.get(i));
190   
191    // allarray.add(strucinarray);
192   
193  0 annotations.addElement(align);
194    // BP.add(align.bps);
195   
196    }
197   
198  0 setSeqs(sqs);
199    }
200   
 
201  0 toggle @Override
202    public String print(SequenceI[] s, boolean jvSuffix)
203    {
204  0 return "not yet implemented";
205    }
206   
 
207  0 toggle public List<RNA> getRNA()
208    {
209  0 return result;
210    }
211   
212    // public static void main(String[] args) {
213    // Pattern p= Pattern.compile("(.+)[.][^.]+");
214    // Matcher m = p.matcher("toto.xml.zip");
215    // jalview.bin.Console.outPrintln(m.matches());
216    // jalview.bin.Console.outPrintln(m.group(1));
217    // }
218    /**
219    * make a friendly ID string.
220    *
221    * @param dataName
222    * @return truncated dataName to after last '/'
223    */
 
224  0 toggle private String safeName(String dataName)
225    {
226  0 int b = 0;
227  0 if ((b = dataName.lastIndexOf(".")) > 0)
228    {
229  0 dataName = dataName.substring(0, b - 1);
230    }
231  0 b = 0;
232  0 Regex m = new Regex("[\\/]?([-A-Za-z0-9]+)\\.?");
233  0 String mm = dataName;
234  0 while (m.searchFrom(dataName, b))
235    {
236  0 mm = m.stringMatched();
237  0 b = m.matchedTo();
238    }
239  0 return mm;
240    }
241    }