- public FastaFile()\r
- {}\r
-\r
- public FastaFile(String inStr) {\r
- super(inStr);\r
- }\r
-\r
- public FastaFile(String inFile, String type) throws IOException {\r
- super(inFile,type);\r
- }\r
-\r
- public void parse() throws IOException\r
- {\r
-\r
- String id = "";\r
- StringBuffer seq = new StringBuffer();\r
- int count = 0;\r
- boolean flag = false;\r
-\r
- int sstart = 0;\r
- int send = 0;\r
-\r
- String line;\r
-\r
- while ((line = nextLine()) != null) {\r
-\r
- if (line.length() > 0) {\r
-\r
- // Do we have an id line?\r
-\r
- if (line.substring(0,1).equals(">")) {\r
-\r
- if (count != 0) {\r
- if (sstart != 0) {\r
- seqs.addElement(new Sequence(id,seq.toString().toUpperCase(),sstart,send));\r
- } else {\r
- seqs.addElement(new Sequence(id,seq.toString().toUpperCase(),1,seq.length()));\r
- }\r
- }\r
-\r
- count++;\r
-\r
- StringTokenizer str = new StringTokenizer(line," ");\r
-\r
- id = str.nextToken();\r
- id = id.substring(1);\r
-\r
- if (id.indexOf("/") > 0 ) {\r
-\r
- StringTokenizer st = new StringTokenizer(id,"/");\r
- if (st.countTokens() == 2) {\r
- id = st.nextToken();\r
- String tmp = st.nextToken();\r
-\r
- st = new StringTokenizer(tmp,"-");\r
-\r
- if (st.countTokens() == 2) {\r
- sstart = Integer.valueOf(st.nextToken()).intValue();\r
- send = Integer.valueOf(st.nextToken()).intValue();\r
- }\r
- }\r
- }\r
-\r
- seq = new StringBuffer();\r
-\r
- } else {\r
- seq = seq.append(line);\r
- }\r
- }\r
- }\r
- if (count > 0) {\r
-\r
- if(!isValidProteinSequence(seq.toString().toUpperCase()))\r
- throw new IOException("Invalid protein sequence");\r
-\r
- if (sstart != 0) {\r
- seqs.addElement(new Sequence(id,seq.toString().toUpperCase(),sstart,send));\r
- } else {\r
- seqs.addElement(new Sequence(id,seq.toString().toUpperCase(),1,seq.length()));\r
- }\r
- }\r
-\r
- }\r
-\r
- public static String print(SequenceI[] s) {\r
- return print(s,72);\r
- }\r
- public static String print(SequenceI[] s, int len) {\r
- return print(s,len,true);\r
- }\r
- public static String print(SequenceI[] s, int len,boolean gaps) {\r
- StringBuffer out = new StringBuffer();\r
- int i = 0;\r
- while (i < s.length && s[i] != null) {\r
- String seq = "";\r
- if (gaps) {\r
- seq = s[i].getSequence();\r
- } else {\r
- seq = AlignSeq.extractGaps("-. ",s[i].getSequence());\r
- }\r
-\r
- out.append(">" + s[i].getName() + "/" + s[i].getStart() + "-" + s[i].getEnd() + "\n");\r