in progress...
[jalview.git] / forester / java / src / org / forester / application / pfamacc2go.java
1 // $Id:
2 //
3 // forester -- software libraries and applications
4 // for genomics and evolutionary biology research.
5 //
6 // Copyright (C) 2010 Christian M Zmasek
7 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
8 // All rights reserved
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 //
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26
27 package org.forester.application;
28
29 import java.io.BufferedReader;
30 import java.io.File;
31 import java.io.FileNotFoundException;
32 import java.io.FileReader;
33 import java.io.IOException;
34 import java.util.List;
35
36 import org.forester.go.PfamToGoMapping;
37 import org.forester.go.PfamToGoParser;
38
39 public class pfamacc2go {
40
41     final static private String PRG_NAME = "pfamacc2go";
42
43     public static void main( final String args[] ) {
44         if ( args.length != 2 ) {
45             printHelp();
46             System.exit( -1 );
47         }
48         final PfamToGoParser p = new PfamToGoParser( new File( args[ 0 ] ) );
49         p.setUseAccessors( true );
50         List<PfamToGoMapping> pfam2go = null;
51         try {
52             pfam2go = p.parse();
53         }
54         catch ( final IOException e ) {
55             printHelp();
56             e.printStackTrace();
57         }
58         BufferedReader br = null;
59         try {
60             br = new BufferedReader( new FileReader( args[ 1 ] ) );
61         }
62         catch ( final FileNotFoundException e ) {
63             printHelp();
64             e.printStackTrace();
65         }
66         String line;
67         int total_pfam_ids = 0;
68         int mapped_pfam_ids = 0;
69         try {
70             while ( ( line = br.readLine() ) != null ) {
71                 line = line.trim();
72                 if ( ( line.length() > 0 ) && !line.startsWith( "#" ) ) {
73                     String[] pfam_ids = null;
74                     if ( line.contains( "," ) ) {
75                         pfam_ids = line.split( "," );
76                     }
77                     else {
78                         pfam_ids = new String[ 1 ];
79                         pfam_ids[ 0 ] = line;
80                     }
81                     for( final String pfam_id : pfam_ids ) {
82                         total_pfam_ids++;
83                         boolean mapped = false;
84                         for( final PfamToGoMapping pfam_to_go_mapping : pfam2go ) {
85                             if ( pfam_to_go_mapping.getKey().equals( pfam_id ) ) {
86                                 mapped = true;
87                                 System.out.println( pfam_to_go_mapping.getValue().toString() );
88                             }
89                         }
90                         if ( mapped ) {
91                             mapped_pfam_ids++;
92                         }
93                     }
94                 }
95             }
96         }
97         catch ( final Exception e ) {
98             printHelp();
99             e.printStackTrace();
100         }
101         System.out.println( "# total pfam ids : " + total_pfam_ids );
102         System.out.println( "# pfam ids mapped: " + mapped_pfam_ids );
103     }
104
105     private static void printHelp() {
106         System.out.println();
107         System.out.println( PRG_NAME
108                             + " <pfam2go mapping file> <file with pfam accessors, newline and/or comma separated>" );
109         System.out.println();
110     }
111 }