2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import jalview.datamodel.*;
29 public static boolean useModellerOutput = false;
31 Vector words = new Vector(); //Stores the words in a line after splitting
37 public PIRFile(String inFile, String type)
42 public PIRFile(FileParse source) throws IOException
49 StringBuffer sequence;
51 ModellerDescription md;
53 while ( (line = nextLine()) != null)
55 if (line.length() == 0)
57 //System.out.println("blank line");
60 if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)
64 Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
66 sequence = new StringBuffer();
68 newSeq.setDescription(nextLine()); // this is the title line
70 boolean starFound = false;
75 sequence.append(line);
82 if (line.indexOf("*") > -1)
88 if (sequence.length() > 0)
90 sequence.setLength(sequence.length() - 1);
91 newSeq.setSequence(sequence.toString());
93 seqs.addElement(newSeq);
95 md = new ModellerDescription(newSeq.
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() + "\n");
134 if (s[i].getDescription() == null)
136 out.append(s[i].getName() + " " +
137 (s[i].getEnd() - s[i].getStart() + 1));
138 out.append(is_NA ? " bases\n" : " residues\n");
142 out.append(s[i].getDescription() + "\n");
148 if (useModellerOutput)
150 out.append(">P1;" + s[i].getName() + "\n");
151 md = new ModellerDescription(s[i]);
152 out.append(md.getDescriptionLine() + "\n");
156 out.append(">P1;" + printId(s[i]) + "\n");
157 if (s[i].getDescription() != null)
159 out.append(s[i].getDescription() + "\n");
163 out.append(s[i].getName() + " "
164 + (s[i].getEnd() - s[i].getStart() + 1)
169 int nochunks = (seq.length() / len) + 1;
171 for (int j = 0; j < nochunks; j++)
174 int end = start + len;
176 if (end < seq.length())
178 out.append(seq.substring(start, end) + "\n");
180 else if (start < seq.length())
182 out.append(seq.substring(start) + "\n");
189 return out.toString();