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.analysis.*;
\r
25 import jalview.datamodel.*;
\r
27 public class PIRFile
\r
30 Vector words = new Vector(); //Stores the words in a line after splitting
\r
36 public PIRFile(String inStr)
\r
41 public PIRFile(String inFile, String type)
\r
44 super(inFile, type);
\r
51 StringBuffer sequence;
\r
54 while ( (line = nextLine()) != null)
\r
56 if(line.length()==0)
\r
58 //System.out.println("blank line");
\r
62 Sequence newSeq = parseId(line.substring(line.indexOf(";") + 1));
\r
64 sequence = new StringBuffer();
\r
66 newSeq.setDescription(nextLine()); // this is the title line
\r
68 boolean starFound = false;
\r
73 sequence.append(line);
\r
78 if (line.indexOf("*") > -1)
\r
84 if(sequence.length()>0)
\r
86 sequence.setLength(sequence.length() - 1);
\r
88 newSeq.setSequence(sequence.toString());
\r
89 seqs.addElement(newSeq);
\r
93 catch (Exception ex)
\r
95 ex.printStackTrace();
\r
99 public String print()
\r
101 return print(getSeqsAsArray());
\r
104 public String print(SequenceI[] s)
\r
106 boolean is_NA = jalview.util.Comparison.isNucleotide(s);
\r
108 StringBuffer out = new StringBuffer();
\r
111 while ( (i < s.length) && (s[i] != null))
\r
113 String seq = s[i].getSequence();
\r
116 out.append(">P1;" + printId(s[i]) + "\n");
\r
118 if(s[i].getDescription()!=null)
\r
119 out.append(s[i].getDescription()+"\n");
\r
122 out.append(s[i].getName()+" "+ (s[i].getEnd() - s[i].getStart() + 1));
\r
123 out.append( is_NA ? " bases\n" : " residues\n");
\r
125 int nochunks = (seq.length() / len) + 1;
\r
127 for (int j = 0; j < nochunks; j++)
\r
129 int start = j * len;
\r
130 int end = start + len;
\r
132 if (end < seq.length())
\r
134 out.append(seq.substring(start, end) + "\n");
\r
136 else if (start < seq.length())
\r
138 out.append(seq.substring(start) + "\n");
\r
145 return out.toString();
\r