2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import jalview.datamodel.*;
26 public class PIRFile extends AlignFile
28 public static boolean useModellerOutput = false;
30 Vector words = new Vector(); // Stores the words in a line after splitting
36 public PIRFile(String inFile, String type) throws IOException
41 public PIRFile(FileParse source) throws IOException
46 public void parse() throws IOException
48 StringBuffer sequence;
50 ModellerDescription md;
52 while ((line = nextLine()) != null)
54 if (line.length() == 0)
56 // System.out.println("blank line");
59 if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)
63 Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
65 sequence = new StringBuffer();
67 newSeq.setDescription(nextLine()); // this is the title line
69 boolean starFound = false;
74 sequence.append(line);
81 if (line.indexOf("*") > -1)
87 if (sequence.length() > 0)
89 sequence.setLength(sequence.length() - 1);
90 newSeq.setSequence(sequence.toString());
92 seqs.addElement(newSeq);
94 md = new ModellerDescription(newSeq.getDescription());
95 md.updateSequenceI(newSeq);
100 public String print()
102 return print(getSeqsAsArray());
105 public String print(SequenceI[] s)
107 boolean is_NA = jalview.util.Comparison.isNucleotide(s);
109 StringBuffer out = new StringBuffer();
111 ModellerDescription md;
113 while ((i < s.length) && (s[i] != null))
115 String seq = s[i].getSequenceAsString();
120 // modeller doesn't really do nucleotides, so we don't do anything fancy
121 // Official tags area as follows, for now we'll use P1 and DL
122 // Protein (complete) P1
123 // Protein (fragment) F1
129 // other functional RNA N1
131 out.append(">N1;" + s[i].getName());
133 if (s[i].getDescription() == null)
135 out.append(s[i].getName() + " "
136 + (s[i].getEnd() - s[i].getStart() + 1));
137 out.append(is_NA ? " bases" : " residues");
142 out.append(s[i].getDescription());
149 if (useModellerOutput)
151 out.append(">P1;" + s[i].getName());
153 md = new ModellerDescription(s[i]);
154 out.append(md.getDescriptionLine());
159 out.append(">P1;" + printId(s[i]));
161 if (s[i].getDescription() != null)
163 out.append(s[i].getDescription());
168 out.append(s[i].getName() + " "
169 + (s[i].getEnd() - s[i].getStart() + 1) + " residues");
174 int nochunks = (seq.length() / len) + 1;
176 for (int j = 0; j < nochunks; j++)
179 int end = start + len;
181 if (end < seq.length())
183 out.append(seq.substring(start, end));
186 else if (start < seq.length())
188 out.append(seq.substring(start));
196 return out.toString();