2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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 inFile, String type)
\r
40 super(inFile, type);
\r
43 public void parse() throws IOException
\r
45 StringBuffer sequence;
\r
47 ModellerDescription md;
\r
49 while ( (line = nextLine()) != null)
\r
51 if (line.length() == 0)
\r
53 //System.out.println("blank line");
\r
56 if (line.indexOf("C;") == 0 || line.indexOf("#") == 0)
\r
60 Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
\r
62 sequence = new StringBuffer();
\r
64 newSeq.setDescription(nextLine()); // this is the title line
\r
66 boolean starFound = false;
\r
71 sequence.append(line);
\r
76 if (line.indexOf("*") > -1)
\r
82 if (sequence.length() > 0)
\r
84 sequence.setLength(sequence.length() - 1);
\r
85 newSeq.setSequence(sequence.toString());
\r
87 seqs.addElement(newSeq);
\r
89 md = new ModellerDescription(newSeq.
\r
91 md.updateSequenceI(newSeq);
\r
96 public String print()
\r
98 return print(getSeqsAsArray());
\r
101 public String print(SequenceI[] s)
\r
103 boolean is_NA = jalview.util.Comparison.isNucleotide(s);
\r
105 StringBuffer out = new StringBuffer();
\r
107 ModellerDescription md;
\r
109 while ( (i < s.length) && (s[i] != null))
\r
111 String seq = s[i].getSequenceAsString();
\r
117 // modeller doesn't really do nucleotides, so we don't do anything fancy
\r
118 // Official tags area as follows, for now we'll use P1 and DL
\r
119 // Protein (complete) P1
\r
120 // Protein (fragment) F1
\r
122 // DNA (circular) DC
\r
124 // RNA (circular) RC
\r
126 // other functional RNA N1
\r
128 out.append(">N1;" + s[i].getName() + "\n");
\r
129 if (s[i].getDescription() == null)
\r
131 out.append(s[i].getName() + " " +
\r
132 (s[i].getEnd() - s[i].getStart() + 1));
\r
133 out.append(is_NA ? " bases\n" : " residues\n");
\r
137 out.append(s[i].getDescription()+"\n");
\r
143 if(useModellerOutput)
\r
145 out.append(">P1;" + s[i].getName() + "\n");
\r
146 md = new ModellerDescription(s[i]);
\r
147 out.append(md.getDescriptionLine() + "\n");
\r
151 out.append(">P1;" + printId(s[i]) + "\n");
\r
152 if (s[i].getDescription() != null)
\r
153 out.append(s[i].getDescription() + "\n");
\r
155 out.append(s[i].getName() + " "
\r
156 + (s[i].getEnd() - s[i].getStart() + 1)
\r
160 int nochunks = (seq.length() / len) + 1;
\r
162 for (int j = 0; j < nochunks; j++)
\r
164 int start = j * len;
\r
165 int end = start + len;
\r
167 if (end < seq.length())
\r
169 out.append(seq.substring(start, end) + "\n");
\r
171 else if (start < seq.length())
\r
173 out.append(seq.substring(start) + "\n");
\r
180 return out.toString();
\r