- public void parse() {\r
- int i = 0;\r
- boolean seqFlag = false;\r
- String key = new String();\r
- Vector headers = new Vector();\r
- Hashtable seqhash = new Hashtable();\r
- String line;\r
-\r
- try {\r
- while ((line = nextLine()) != null) {\r
- StringTokenizer str = new StringTokenizer(line);\r
-\r
- while (str.hasMoreTokens()) {\r
- String inStr = str.nextToken();\r
-\r
- //If line has header information add to the headers vector\r
- if (inStr.indexOf("Name:") != -1) {\r
- key = str.nextToken();\r
- headers.addElement(key);\r
- }\r
-\r
- //if line has // set SeqFlag to 1 so we know sequences are coming\r
- if (inStr.indexOf("//") != -1) {\r
- seqFlag = true;\r
- }\r
-\r
- //Process lines as sequence lines if seqFlag is set\r
- if ((inStr.indexOf("//") == -1) && (seqFlag == true)) {\r
- //seqeunce id is the first field\r
- key = inStr;\r
-\r
- StringBuffer tempseq;\r
-\r
- //Get sequence from hash if it exists\r
- if (seqhash.containsKey(key)) {\r
- tempseq = (StringBuffer) seqhash.get(key);\r
- } else {\r
- tempseq = new StringBuffer();\r
- seqhash.put(key, tempseq);\r
- }\r
-\r
- //loop through the rest of the words\r
- while (str.hasMoreTokens()) {\r
- //append the word to the sequence\r
- tempseq.append(str.nextToken());\r
- }\r
- }\r
- }\r
- }\r
- } catch (IOException e) {\r
- System.err.println("Exception parsing PileUpfile " + e);\r
- e.printStackTrace();\r
- }\r
-\r
- this.noSeqs = headers.size();\r
-\r
- //Add sequences to the hash\r
- for (i = 0; i < headers.size(); i++) {\r
- if (seqhash.get(headers.elementAt(i)) != null) {\r
- String head = headers.elementAt(i).toString();\r
- String seq = seqhash.get(head).toString();\r
-\r
- int start = 1;\r
- int end = seq.length();\r
-\r
- if (maxLength < head.length()) {\r
- maxLength = head.length();\r
- }\r
-\r
- if (head.indexOf("/") > 0) {\r
- StringTokenizer st = new StringTokenizer(head, "/");\r
-\r
- if (st.countTokens() == 2) {\r
- head = st.nextToken();\r
-\r
- String tmp = st.nextToken();\r
- st = new StringTokenizer(tmp, "-");\r
-\r
- if (st.countTokens() == 2) {\r
- start = Integer.valueOf(st.nextToken()).intValue();\r
- end = Integer.valueOf(st.nextToken()).intValue();\r
- }\r
- }\r
- }\r
-\r
- Sequence newSeq = new Sequence(head, seq, start, end);\r
-\r
- seqs.addElement(newSeq);\r
- } else {\r
- System.err.println(\r
- "PileUpfile Parser: Can't find sequence for " +\r
- headers.elementAt(i));\r
- }\r
- }\r