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/>.
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;
30 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
32 import jalview.datamodel.*;
34 public class PIRFile extends AlignFile
36 public static boolean useModellerOutput = false;
38 Vector words = new Vector(); // Stores the words in a line after splitting
44 public PIRFile(String inFile, String type) throws Exception
49 public PIRFile(FileParse source) throws Exception
54 public void parse() throws IOException
56 StringBuffer sequence;
58 ModellerDescription md;
60 while ((line = nextLine()) != null)
62 if (line.length() == 0)
64 // System.out.println("blank line");
67 if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)
71 Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
73 sequence = new StringBuffer();
75 newSeq.setDescription(nextLine()); // this is the title line
77 boolean starFound = false;
82 sequence.append(line);
89 if (line.indexOf("*") > -1)
95 if (sequence.length() > 0)
97 sequence.setLength(sequence.length() - 1);
98 newSeq.setSequence(sequence.toString());
100 seqs.addElement(newSeq);
102 md = new ModellerDescription(newSeq.getDescription());
103 md.updateSequenceI(newSeq);
108 public String print()
110 return print(getSeqsAsArray());
113 public String print(SequenceI[] s)
115 boolean is_NA = jalview.util.Comparison.isNucleotide(s);
117 StringBuffer out = new StringBuffer();
119 ModellerDescription md;
121 while ((i < s.length) && (s[i] != null))
123 String seq = s[i].getSequenceAsString();
128 // modeller doesn't really do nucleotides, so we don't do anything fancy
129 // Official tags area as follows, for now we'll use P1 and DL
130 // Protein (complete) P1
131 // Protein (fragment) F1
137 // other functional RNA N1
139 out.append(">N1;" + s[i].getName());
141 if (s[i].getDescription() == null)
143 out.append(s[i].getName() + " "
144 + (s[i].getEnd() - s[i].getStart() + 1));
145 out.append(is_NA ? " bases" : " residues");
150 out.append(s[i].getDescription());
157 if (useModellerOutput)
159 out.append(">P1;" + s[i].getName());
161 md = new ModellerDescription(s[i]);
162 out.append(md.getDescriptionLine());
167 out.append(">P1;" + printId(s[i]));
169 if (s[i].getDescription() != null)
171 out.append(s[i].getDescription());
176 out.append(s[i].getName() + " "
177 + (s[i].getEnd() - s[i].getStart() + 1) + " residues");
182 int nochunks = (seq.length() / len) + 1;
184 for (int j = 0; j < nochunks; j++)
187 int end = start + len;
189 if (end < seq.length())
191 out.append(seq.substring(start, end));
194 else if (start < seq.length())
196 out.append(seq.substring(start));
204 return out.toString();