2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
24 import jalview.datamodel.*;
\r
26 public class PIRFile
\r
29 public static boolean useModellerOutput = false;
\r
31 Vector words = new Vector(); //Stores the words in a line after splitting
\r
37 public PIRFile(String inStr)
\r
42 public PIRFile(String inFile, String type)
\r
45 super(inFile, type);
\r
48 public void parse() throws IOException
\r
50 StringBuffer sequence;
\r
52 ModellerDescription md;
\r
54 while ( (line = nextLine()) != null)
\r
56 if (line.length() == 0)
\r
58 //System.out.println("blank line");
\r
61 if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)
\r
65 Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
\r
67 sequence = new StringBuffer();
\r
69 newSeq.setDescription(nextLine()); // this is the title line
\r
71 boolean starFound = false;
\r
76 sequence.append(line);
\r
81 if (line.indexOf("*") > -1)
\r
87 if (sequence.length() > 0)
\r
89 sequence.setLength(sequence.length() - 1);
\r
90 newSeq.setSequence(sequence.toString());
\r
91 if (!isValidProteinSequence(newSeq.getSequence()))
\r
93 throw new IOException(AppletFormatAdapter.INVALID_CHARACTERS
\r
94 +" : "+ newSeq.getName()
\r
95 +" : "+invalidCharacter);
\r
98 seqs.addElement(newSeq);
\r
100 md = new ModellerDescription(newSeq.
\r
102 md.updateSequenceI(newSeq);
\r
107 public String print()
\r
109 return print(getSeqsAsArray());
\r
112 public String print(SequenceI[] s)
\r
114 boolean is_NA = jalview.util.Comparison.isNucleotide(s);
\r
116 StringBuffer out = new StringBuffer();
\r
118 ModellerDescription md;
\r
120 while ( (i < s.length) && (s[i] != null))
\r
122 String seq = s[i].getSequence();
\r
128 // modeller doesn't really do nucleotides, so we don't do anything fancy
\r
129 // Official tags area as follows, for now we'll use P1 and DL
\r
130 // Protein (complete) P1
\r
131 // Protein (fragment) F1
\r
133 // DNA (circular) DC
\r
135 // RNA (circular) RC
\r
137 // other functional RNA N1
\r
139 out.append(">N1;" + s[i].getName() + "\n");
\r
140 if (s[i].getDescription() == null)
\r
142 out.append(s[i].getName() + " " +
\r
143 (s[i].getEnd() - s[i].getStart() + 1));
\r
144 out.append(is_NA ? " bases\n" : " residues\n");
\r
148 out.append(s[i].getDescription()+"\n");
\r
154 if(useModellerOutput)
\r
156 out.append(">P1;" + s[i].getName() + "\n");
\r
157 md = new ModellerDescription(s[i]);
\r
158 out.append(md.getDescriptionLine() + "\n");
\r
162 out.append(">P1;" + printId(s[i]) + "\n");
\r
163 if (s[i].getDescription() != null)
\r
164 out.append(s[i].getDescription() + "\n");
\r
166 out.append(s[i].getName() + " "
\r
167 + (s[i].getEnd() - s[i].getStart() + 1)
\r
171 int nochunks = (seq.length() / len) + 1;
\r
173 for (int j = 0; j < nochunks; j++)
\r
175 int start = j * len;
\r
176 int end = start + len;
\r
178 if (end < seq.length())
\r
180 out.append(seq.substring(start, end) + "\n");
\r
182 else if (start < seq.length())
\r
184 out.append(seq.substring(start) + "\n");
\r
191 return out.toString();
\r