1 /* Jalview - a java multiple alignment editor
\r
2 * Copyright (C) 1998 Michele Clamp
\r
4 * This program is free software; you can redistribute it and/or
\r
5 * modify it under the terms of the GNU General Public License
\r
6 * as published by the Free Software Foundation; either version 2
\r
7 * of the License, or (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License
\r
15 * along with this program; if not, write to the Free Software
\r
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
20 import jalview.datamodel.*;
\r
21 import jalview.analysis.*;
\r
26 public class PIRFile extends AlignFile {
\r
28 Vector words = new Vector(); //Stores the words in a line after splitting
\r
33 public PIRFile(String inStr) {
\r
37 public PIRFile(String inFile, String type) throws IOException {
\r
41 public void parse() {
\r
43 String id, start, end;
\r
44 StringBuffer sequence;
\r
46 while( (line = nextLine())!=null)
\r
49 id = line.substring(line.indexOf(";") + 1, line.indexOf("/"));
\r
50 line = line.substring(line.indexOf("/") + 1);
\r
51 start = line.substring(0, line.indexOf("-"));
\r
52 end = line.substring(line.indexOf("-") + 1);
\r
53 }catch(Exception ex)
\r
54 { id="No id"; start="0"; end="0"; }
\r
56 sequence = new StringBuffer();
\r
58 line = nextLine(); // this is the title line
\r
60 boolean starFound = false;
\r
64 sequence.append( line );
\r
65 if(line.indexOf("*")>-1)
\r
70 sequence.setLength( sequence.length()-1);
\r
72 Sequence newSeq = new Sequence(id,
\r
73 sequence.toString(),
\r
74 Integer.parseInt(start),
\r
75 Integer.parseInt(end));
\r
76 seqs.addElement(newSeq);
\r
80 catch(Exception ex){ex.printStackTrace();}
\r
83 public String print() {
\r
84 return print(getSeqsAsArray());
\r
86 public static String print(SequenceI[] s) {
\r
87 return print(s,72,true);
\r
89 public static String print(SequenceI[] s, int len) {
\r
90 return print(s,len,true);
\r
92 public static String print(SequenceI[] s, int len,boolean gaps) {
\r
93 StringBuffer out = new StringBuffer();
\r
96 while (i < s.length && s[i] != null) {
\r
99 seq = s[i].getSequence() + "*";
\r
101 seq = AlignSeq.extractGaps(s[i].getSequence(),"-");
\r
102 seq = AlignSeq.extractGaps(seq,".");
\r
103 seq = AlignSeq.extractGaps(seq," ");
\r
107 out.append(">P1;" + s[i].getName() + "/" + s[i].getStart()+ "-" + s[i].getEnd() + "\n");
\r
108 out.append(" Dummy title\n");
\r
109 int nochunks = seq.length() / len + 1;
\r
111 for (int j = 0; j < nochunks; j++) {
\r
113 int end = start + len;
\r
115 if (end < seq.length()) {
\r
116 out.append(seq.substring(start,end) + "\n");
\r
117 } else if (start < seq.length()) {
\r
118 out.append(seq.substring(start) + "\n");
\r
123 return out.toString();
\r
126 public static void main(String[] args) {
\r
127 String inStr = ">P1;LCAT_MOUSE_90.35\nMGLPGSPWQRVLLLLGLLLPPATPFWLLNVLFPPHTTPKAELSNHTRPVILVPGCLGNRLEAKLDKPDVVNW\nMCYRKTEDFFTIWLDFNLFLPLGVDCWIDNTRIVYNHSSGRVSNAPGVQIRVPGFGKTESVEYVDDNKLAGY\n\n>LCAT_PAPAN_95.78\nMGPPGSPWQWVPLLLGLLLPPAAPFWLLNVLFPPHTTPKAELSNHTRPVILVPGCLGNQLEAKLDKPDVVNW\nMCYRKTEDFFTIWLDLNMFLPLGVDCWIDNTRVVYNRSSGLVSNAPGVQIRVPGFGKTYSVEYLDSSKLAGY\nLHTLVQNLVNNGYVRDETVRAAPYDWRLEPGQQEEYYHKLAGLVEEMHAAYGKPVFLIGHSLGCLHLLYFLL\n";
\r
128 PIRFile fa = new PIRFile(inStr);
\r