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
54 StringBuffer sequence;
\r
57 while ( (line = nextLine()) != null)
\r
59 if(line.length()==0)
\r
61 //System.out.println("blank line");
\r
71 int slashIndex = line.indexOf("/");
\r
74 id = line.substring(line.indexOf(";") + 1, line.indexOf("/"));
\r
75 line = line.substring(line.indexOf("/") + 1);
\r
76 start = line.substring(0, line.indexOf("-"));
\r
77 end = line.substring(line.indexOf("-") + 1);
\r
81 id = line.substring(line.indexOf(";")+1);
\r
84 catch (Exception ex)
\r
85 { }// Default id, start and end unchanged
\r
87 sequence = new StringBuffer();
\r
89 line = nextLine(); // this is the title line
\r
91 boolean starFound = false;
\r
96 sequence.append(line);
\r
101 if (line.indexOf("*") > -1)
\r
107 if(sequence.length()>0)
\r
109 sequence.setLength(sequence.length() - 1);
\r
111 Sequence newSeq = new Sequence(id, sequence.toString(),
\r
112 Integer.parseInt(start),
\r
113 Integer.parseInt(end));
\r
114 seqs.addElement(newSeq);
\r
118 catch (Exception ex)
\r
120 ex.printStackTrace();
\r
124 public String print()
\r
126 return print(getSeqsAsArray());
\r
129 public static String print(SequenceI[] s)
\r
131 return print(s, 72, true);
\r
134 public static String print(SequenceI[] s, int len)
\r
136 return print(s, len, true);
\r
139 public static String print(SequenceI[] s, int len, boolean gaps)
\r
141 StringBuffer out = new StringBuffer();
\r
144 while ( (i < s.length) && (s[i] != null))
\r
150 seq = s[i].getSequence() + "*";
\r
154 seq = AlignSeq.extractGaps(s[i].getSequence(), "-");
\r
155 seq = AlignSeq.extractGaps(seq, ".");
\r
156 seq = AlignSeq.extractGaps(seq, " ");
\r
160 out.append(">P1;" + s[i].getName() + "/" + s[i].getStart() + "-" +
\r
161 s[i].getEnd() + "\n");
\r
162 out.append(" Dummy title\n");
\r
164 int nochunks = (seq.length() / len) + 1;
\r
166 for (int j = 0; j < nochunks; j++)
\r
168 int start = j * len;
\r
169 int end = start + len;
\r
171 if (end < seq.length())
\r
173 out.append(seq.substring(start, end) + "\n");
\r
175 else if (start < seq.length())
\r
177 out.append(seq.substring(start) + "\n");
\r
184 return out.toString();
\r
187 public static void main(String[] args)
\r
189 String inStr = ">P1;LCAT_MOUSE_90.35\nMGLPGSPWQRVLLLLGLLLPPATPFWLLNVLFPPHTTPKAELSNHTRPVILVPGCLGNRLEAKLDKPDVVNW\nMCYRKTEDFFTIWLDFNLFLPLGVDCWIDNTRIVYNHSSGRVSNAPGVQIRVPGFGKTESVEYVDDNKLAGY\n\n>LCAT_PAPAN_95.78\nMGPPGSPWQWVPLLLGLLLPPAAPFWLLNVLFPPHTTPKAELSNHTRPVILVPGCLGNQLEAKLDKPDVVNW\nMCYRKTEDFFTIWLDLNMFLPLGVDCWIDNTRVVYNRSSGLVSNAPGVQIRVPGFGKTYSVEYLDSSKLAGY\nLHTLVQNLVNNGYVRDETVRAAPYDWRLEPGQQEEYYHKLAGLVEEMHAAYGKPVFLIGHSLGCLHLLYFLL\n";
\r
190 PIRFile fa = new PIRFile(inStr);
\r