2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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 jalview.datamodel.*;
25 public class PIRFile extends AlignFile
27 public static boolean useModellerOutput = false;
29 Vector words = new Vector(); // Stores the words in a line after splitting
35 public PIRFile(String inFile, String type) throws IOException
40 public PIRFile(FileParse source) throws IOException
45 public void parse() throws IOException
47 StringBuffer sequence;
49 ModellerDescription md;
51 while ((line = nextLine()) != null)
53 if (line.length() == 0)
55 // System.out.println("blank line");
58 if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)
62 Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
64 sequence = new StringBuffer();
66 newSeq.setDescription(nextLine()); // this is the title line
68 boolean starFound = false;
73 sequence.append(line);
80 if (line.indexOf("*") > -1)
86 if (sequence.length() > 0)
88 sequence.setLength(sequence.length() - 1);
89 newSeq.setSequence(sequence.toString());
91 seqs.addElement(newSeq);
93 md = new ModellerDescription(newSeq.getDescription());
94 md.updateSequenceI(newSeq);
101 return print(getSeqsAsArray());
104 public String print(SequenceI[] s)
106 boolean is_NA = jalview.util.Comparison.isNucleotide(s);
108 StringBuffer out = new StringBuffer();
110 ModellerDescription md;
112 while ((i < s.length) && (s[i] != null))
114 String seq = s[i].getSequenceAsString();
119 // modeller doesn't really do nucleotides, so we don't do anything fancy
120 // Official tags area as follows, for now we'll use P1 and DL
121 // Protein (complete) P1
122 // Protein (fragment) F1
128 // other functional RNA N1
130 out.append(">N1;" + s[i].getName());
132 if (s[i].getDescription() == null)
134 out.append(s[i].getName() + " "
135 + (s[i].getEnd() - s[i].getStart() + 1));
136 out.append(is_NA ? " bases" : " residues");
141 out.append(s[i].getDescription());
148 if (useModellerOutput)
150 out.append(">P1;" + s[i].getName());
152 md = new ModellerDescription(s[i]);
153 out.append(md.getDescriptionLine());
158 out.append(">P1;" + printId(s[i]));
160 if (s[i].getDescription() != null)
162 out.append(s[i].getDescription());
167 out.append(s[i].getName() + " "
168 + (s[i].getEnd() - s[i].getStart() + 1) + " residues");
173 int nochunks = (seq.length() / len) + 1;
175 for (int j = 0; j < nochunks; j++)
178 int end = start + len;
180 if (end < seq.length())
182 out.append(seq.substring(start, end));
185 else if (start < seq.length())
187 out.append(seq.substring(start));
195 return out.toString();