2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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/>.
23 import javax.xml.parsers.ParserConfigurationException;
25 import org.xml.sax.SAXException;
27 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
28 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
29 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
31 import jalview.datamodel.*;
33 public class PIRFile extends AlignFile
35 public static boolean useModellerOutput = false;
37 Vector words = new Vector(); // Stores the words in a line after splitting
43 public PIRFile(String inFile, String type) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
48 public PIRFile(FileParse source) throws IOException, ExceptionFileFormatOrSyntax, ParserConfigurationException, SAXException, ExceptionPermissionDenied, ExceptionLoadingFailed
53 public void parse() throws IOException
55 StringBuffer sequence;
57 ModellerDescription md;
59 while ((line = nextLine()) != null)
61 if (line.length() == 0)
63 // System.out.println("blank line");
66 if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)
70 Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
72 sequence = new StringBuffer();
74 newSeq.setDescription(nextLine()); // this is the title line
76 boolean starFound = false;
81 sequence.append(line);
88 if (line.indexOf("*") > -1)
94 if (sequence.length() > 0)
96 sequence.setLength(sequence.length() - 1);
97 newSeq.setSequence(sequence.toString());
99 seqs.addElement(newSeq);
101 md = new ModellerDescription(newSeq.getDescription());
102 md.updateSequenceI(newSeq);
107 public String print()
109 return print(getSeqsAsArray());
112 public String print(SequenceI[] s)
114 boolean is_NA = jalview.util.Comparison.isNucleotide(s);
116 StringBuffer out = new StringBuffer();
118 ModellerDescription md;
120 while ((i < s.length) && (s[i] != null))
122 String seq = s[i].getSequenceAsString();
127 // modeller doesn't really do nucleotides, so we don't do anything fancy
128 // Official tags area as follows, for now we'll use P1 and DL
129 // Protein (complete) P1
130 // Protein (fragment) F1
136 // other functional RNA N1
138 out.append(">N1;" + s[i].getName());
140 if (s[i].getDescription() == null)
142 out.append(s[i].getName() + " "
143 + (s[i].getEnd() - s[i].getStart() + 1));
144 out.append(is_NA ? " bases" : " residues");
149 out.append(s[i].getDescription());
156 if (useModellerOutput)
158 out.append(">P1;" + s[i].getName());
160 md = new ModellerDescription(s[i]);
161 out.append(md.getDescriptionLine());
166 out.append(">P1;" + printId(s[i]));
168 if (s[i].getDescription() != null)
170 out.append(s[i].getDescription());
175 out.append(s[i].getName() + " "
176 + (s[i].getEnd() - s[i].getStart() + 1) + " residues");
181 int nochunks = (seq.length() / len) + 1;
183 for (int j = 0; j < nochunks; j++)
186 int end = start + len;
188 if (end < seq.length())
190 out.append(seq.substring(start, end));
193 else if (start < seq.length())
195 out.append(seq.substring(start));
203 return out.toString();