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 java.io.BufferedReader;
21 import java.io.FileNotFoundException;
22 import java.io.FileReader;
23 import java.util.ArrayList;
24 import java.util.Vector;
25 import java.util.regex.Matcher;
26 import java.util.regex.Pattern;
28 import jalview.analysis.SecStrConsensus;
29 import jalview.analysis.SecStrConsensus.SimpleBP;
30 import jalview.datamodel.AlignmentAnnotation;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.SecondaryStructureAnnotation;
33 import jalview.datamodel.Sequence;
34 import jalview.datamodel.SequenceFeature;
35 import jalview.datamodel.SequenceI;
37 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
38 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
39 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
40 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
41 import fr.orsay.lri.varna.factories.RNAFactory;
42 import fr.orsay.lri.varna.factories.RNAFactory.RNAFileType;
43 import fr.orsay.lri.varna.models.rna.RNA;
44 import fr.orsay.lri.varna.utils.RNAMLParser;
46 public class RnamlFile extends AlignFile {
48 public String namefile;
50 protected ArrayList<RNA> result;
57 public RnamlFile(String inFile, String type) throws Exception {
62 public RnamlFile(FileParse source) throws Exception {
67 public BufferedReader CreateReader() throws FileNotFoundException {
69 fr = new FileReader(inFile);
71 BufferedReader r = new BufferedReader(fr);
75 @SuppressWarnings("unchecked")
76 public void parse() throws FileNotFoundException,
77 ExceptionPermissionDenied, ExceptionLoadingFailed,
78 ExceptionFileFormatOrSyntax {
80 result = RNAFactory.loadSecStrRNAML(getReader());
82 ArrayList<ArrayList> allarray = new ArrayList();
83 ArrayList<ArrayList<SimpleBP>> BP = new ArrayList();
84 ArrayList strucinarray = new ArrayList();
85 SequenceI[] seqs = new SequenceI[result.size()];
86 namefile = inFile.getName();
88 for (int i = 0; i < result.size(); i++) {
90 RNA current = result.get(i);
91 String rna = current.getStructDBN(true);
92 String seq = current.getSeq();
96 System.out.println("id=" + i);
97 name = this.safeName(namefile, i);
98 seqs[i] = new Sequence(name, seq, begin, end);
100 seqs[i].setEnd(seqs[i].findPosition(seqs[i].getLength()));
101 String[] annot = new String[rna.length()];
102 Annotation[] ann = new Annotation[rna.length()];
104 for (int j = 0; j < rna.length(); j++) {
105 annot[j] = "" + rna.charAt(j);
108 for (int k = 0; k < rna.length(); k++) {
109 ann[k] = new Annotation(annot[k], "",
110 jalview.schemes.ResidueProperties.getRNASecStrucState(
111 annot[k]).charAt(0), 0f);
114 AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",
115 current.getID(), ann);
117 seqs[i].addAlignmentAnnotation(align);
118 seqs[i].setRNA(result.get(i));
120 char[] struc = align.getRNAStruc().toCharArray();
122 allarray.add(strucinarray);
124 this.annotations.addElement(align);
129 int[] tab = SecStrConsensus.extractConsensus(BP);
134 public void parse(BufferedReader r) throws ExceptionPermissionDenied,
135 ExceptionLoadingFailed, ExceptionFileFormatOrSyntax {
137 result = RNAFactory.loadSecStrRNAML(r);
139 ArrayList<ArrayList> allarray = new ArrayList();
140 ArrayList<ArrayList<SimpleBP>> BP = new ArrayList();
141 ArrayList strucinarray = new ArrayList();
142 SequenceI[] seqs = new SequenceI[result.size()];
143 namefile = inFile.getName();
145 for (int i = 0; i < result.size(); i++) {
147 RNA current = result.get(i);
148 String rna = current.getStructDBN(true);
150 String seq = current.getSeq();
154 name = this.safeName(namefile, i);
155 seqs[i] = new Sequence(name, seq, begin, end);
157 seqs[i].setEnd(seqs[i].findPosition(seqs[i].getLength()));
158 String[] annot = new String[rna.length()];
159 Annotation[] ann = new Annotation[rna.length()];
161 for (int j = 0; j < rna.length(); j++) {
162 annot[j] = "" + rna.charAt(j);
165 for (int k = 0; k < rna.length(); k++) {
166 ann[k] = new Annotation(annot[k], "",
167 jalview.schemes.ResidueProperties.getRNASecStrucState(
168 annot[k]).charAt(0), 0f);
171 AlignmentAnnotation align = new AlignmentAnnotation("Sec. str.",
172 current.getID(), ann);
174 seqs[i].addAlignmentAnnotation(align);
175 seqs[i].setRNA(result.get(i));
177 char[] struc = align.getRNAStruc().toCharArray();
178 for (int y = 0; y < struc.length; y++) {
179 strucinarray.add(struc[y]);
180 // System.out.println("structy"+struc[y]);
182 // System.out.println("Sequence"+i+"\t : "+strucinarray.toString());
183 allarray.add(strucinarray);
185 this.annotations.addElement(align);
186 System.out.println(rna);
188 System.out.println(align.bps.size());
191 int[] tab = SecStrConsensus.extractConsensus(BP);
198 public static String print(SequenceI[] s) {
199 return "not yet implemented";
202 public String print() {
203 System.out.print("print :");
204 return print(getSeqsAsArray());
207 public ArrayList getRNA() {
211 public Vector getAnnot() {
215 // public static void main(String[] args) {
216 // Pattern p= Pattern.compile("(.+)[.][^.]+");
217 // Matcher m = p.matcher("toto.xml.zip");
218 // System.out.println(m.matches());
219 // System.out.println(m.group(1));
221 public String safeName(String namefile, int id) {
223 Pattern p = Pattern.compile("(.*)[.][^.]+");
224 Matcher m = p.matcher(namefile);
225 name = m.group(1) + "_" + id;