771f3f46f42eeef3ae6c07b0c5f8d36c33a3135d
[jabaws.git] / runner / compbio / pipeline / _jpred / JackHmmerHitParser.java
1 /* Copyright (c) 2011 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.pipeline._jpred;\r
19 \r
20 import java.io.BufferedReader;\r
21 import java.io.FileInputStream;\r
22 import java.io.IOException;\r
23 import java.io.InputStreamReader;\r
24 import java.util.ArrayList;\r
25 import java.util.Collections;\r
26 import java.util.HashSet;\r
27 import java.util.List;\r
28 import java.util.Scanner;\r
29 import java.util.Set;\r
30 \r
31 /**\r
32  * Parser for the following files:\r
33  * \r
34  * @author pvtroshin\r
35  * \r
36  */\r
37 public class JackHmmerHitParser {\r
38     //#                                                                      --- full sequence ---- --- best 1 domain ---- --- domain number estimation ----\r
39     //# target name          accession  query name                accession    E-value  score  bias   E-value  score  bias   exp reg clu  ov env dom rep inc description of target\r
40     //#  ------------------- ----------      -------------------- ---------- --------- ------ ----- --------- ------ -----   --- --- --- --- --- --- --- --- ---------------------\r
41     //tr|Q6TVU2|Q6TVU2_ORFV  -          gi_74230740_gb_ABA00545.1 -           4.5e-271  910.4   0.0  5.1e-271  910.2   0.0   1.0   1   0   0   1   1   1   1 Putative uncharacterized protein OS=Orf virus PE=4 SV=1\r
42 \r
43     Set<Hit> hits;\r
44 \r
45     public JackHmmerHitParser(String file) throws IOException {\r
46 \r
47         BufferedReader bfr = new BufferedReader(new InputStreamReader(\r
48                 new FileInputStream(file), "ISO-8859-1"), 64000);\r
49         // throw away first three lines; \r
50         this.hits = new HashSet<Hit>();\r
51         String line = bfr.readLine();\r
52         bfr.readLine();\r
53         bfr.readLine();\r
54         int hitc = 0;\r
55         while ((line = bfr.readLine()) != null) {\r
56             hitc++;\r
57             Scanner scan = new Scanner(line);\r
58             scan.useDelimiter("\\s+");\r
59             extractData(scan, hitc);\r
60         }\r
61         List<Hit> lhits = new ArrayList<Hit>(hits);\r
62         Collections.sort(lhits, new Hit.NumberComporator());\r
63     }\r
64 \r
65     void extractData(Scanner scan, int hitcounter) {\r
66         Hit pseq = new Hit();\r
67 \r
68         String tname = scan.next();\r
69         pseq.name = tname;\r
70         //System.out.println(tname);\r
71 \r
72         String tacc = scan.next();\r
73         pseq.accession = tacc;\r
74         //System.out.println(tacc);\r
75         String qname = scan.next();\r
76         //System.out.println(qname);\r
77         String qacc = scan.next();\r
78         //System.out.println(qacc);\r
79 \r
80         Double evalue = scan.nextDouble();\r
81         //System.out.println(evalue);\r
82         pseq.evalue = evalue.toString();\r
83 \r
84         Double score = scan.nextDouble();\r
85         //System.out.println(score);\r
86         pseq.evalue = evalue.toString();\r
87         pseq.number = new Integer(hitcounter).toString();\r
88         boolean unique = hits.add(pseq);\r
89         assert unique : "Unique hits are expected!";\r
90     }\r
91 \r
92     public static void main(String[] args) throws IOException {\r
93         assert args[0] != null;\r
94         JackHmmerHitParser parser = new JackHmmerHitParser(args[0]);\r
95         BlastParser.printHits(parser.hits);\r
96     }\r
97 }\r