2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
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.
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.
26 import jalview.datamodel.*;
28 public class PIRFile extends AlignFile
30 public static boolean useModellerOutput = false;
32 Vector words = new Vector(); // Stores the words in a line after splitting
38 public PIRFile(String inFile, String type) throws IOException
43 public PIRFile(FileParse source) throws IOException
48 public void parse() throws IOException
50 StringBuffer sequence;
52 ModellerDescription md;
54 while ((line = nextLine()) != null)
56 if (line.length() == 0)
58 // System.out.println("blank line");
61 if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)
65 Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
67 sequence = new StringBuffer();
69 newSeq.setDescription(nextLine()); // this is the title line
71 boolean starFound = false;
76 sequence.append(line);
83 if (line.indexOf("*") > -1)
89 if (sequence.length() > 0)
91 sequence.setLength(sequence.length() - 1);
92 newSeq.setSequence(sequence.toString());
94 seqs.addElement(newSeq);
96 md = new ModellerDescription(newSeq.getDescription());
97 md.updateSequenceI(newSeq);
102 public String print()
104 return print(getSeqsAsArray());
107 public String print(SequenceI[] s)
109 boolean is_NA = jalview.util.Comparison.isNucleotide(s);
111 StringBuffer out = new StringBuffer();
113 ModellerDescription md;
115 while ((i < s.length) && (s[i] != null))
117 String seq = s[i].getSequenceAsString();
122 // modeller doesn't really do nucleotides, so we don't do anything fancy
123 // Official tags area as follows, for now we'll use P1 and DL
124 // Protein (complete) P1
125 // Protein (fragment) F1
131 // other functional RNA N1
133 out.append(">N1;" + s[i].getName());
135 if (s[i].getDescription() == null)
137 out.append(s[i].getName() + " "
138 + (s[i].getEnd() - s[i].getStart() + 1));
139 out.append(is_NA ? " bases" : " residues");
144 out.append(s[i].getDescription());
151 if (useModellerOutput)
153 out.append(">P1;" + s[i].getName());
155 md = new ModellerDescription(s[i]);
156 out.append(md.getDescriptionLine());
161 out.append(">P1;" + printId(s[i]));
163 if (s[i].getDescription() != null)
165 out.append(s[i].getDescription());
170 out.append(s[i].getName() + " "
171 + (s[i].getEnd() - s[i].getStart() + 1) + " residues");
176 int nochunks = (seq.length() / len) + 1;
178 for (int j = 0; j < nochunks; j++)
181 int end = start + len;
183 if (end < seq.length())
185 out.append(seq.substring(start, end));
188 else if (start < seq.length())
190 out.append(seq.substring(start));
198 return out.toString();