2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2009 Christian M. Zmasek
6 // Copyright (C) 2009 Burnham Institute for Medical Research
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.application;
28 import java.io.BufferedReader;
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.HashSet;
33 import java.util.List;
36 import org.forester.go.PfamToGoMapping;
37 import org.forester.go.PfamToGoParser;
38 import org.forester.util.CommandLineArguments;
39 import org.forester.util.ForesterUtil;
41 public class pfam_go {
43 final static private String HELP_OPTION_1 = "help";
44 final static private String HELP_OPTION_2 = "h";
45 final static private String PRG_NAME = "pfam2go";
46 final static private String PRG_VERSION = "1.00";
47 final static private String PRG_DATE = "2010.02.02";
48 final static private String E_MAIL = "czmasek@burnham.org";
49 final static private String WWW = "www.phylosoft.org";
51 private static void doit( final File pfams_file, final List<PfamToGoMapping> mappings ) throws IOException {
52 final BufferedReader reader = ForesterUtil.obtainReader( pfams_file );
55 int not_found_count = 0;
56 final Set<String> encountered_domains = new HashSet<String>();
57 while ( ( line = reader.readLine() ) != null ) {
59 if ( ForesterUtil.isEmpty( line ) || line.startsWith( "##" ) ) {
62 else if ( line.startsWith( "#" ) ) {
63 encountered_domains.clear();
64 line = line.replace( '#', '>' );
65 System.out.println( line );
68 if ( !encountered_domains.contains( line ) ) {
69 encountered_domains.add( line );
70 boolean found = false;
71 for( final PfamToGoMapping mapping : mappings ) {
72 if ( mapping.getKey().getId().equals( line ) ) {
73 System.out.println( mapping.getValue() );
85 System.err.println( "# duplicate domain: " + line );
89 System.out.println( "# pfams with mapping to GO : " + found_count );
90 System.out.println( "# pfams without mapping to GO: " + not_found_count );
94 public static void main( final String args[] ) {
95 CommandLineArguments cla = null;
97 cla = new CommandLineArguments( args );
99 catch ( final Exception e ) {
100 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
102 if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) || ( args.length == 0 ) ) {
106 final List<String> allowed_options = new ArrayList<String>();
107 if ( cla.getNumberOfNames() != 2 ) {
111 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
112 if ( dissallowed_options.length() > 0 ) {
113 ForesterUtil.fatalError( PRG_NAME, "unknown option(s): " + dissallowed_options );
115 final File pfam2go_file = cla.getFile( 0 );
116 final File pfams_file = cla.getFile( 1 );
117 final PfamToGoParser pfam2go_parser = new PfamToGoParser( pfam2go_file );
118 List<PfamToGoMapping> mappings = null;
120 mappings = pfam2go_parser.parse();
122 catch ( final IOException e ) {
126 doit( pfams_file, mappings );
128 catch ( final IOException e ) {
131 System.out.println();
134 private static void printHelp() {
135 ForesterUtil.printProgramInformation( PRG_NAME, PRG_VERSION, PRG_DATE, E_MAIL, WWW );
136 System.out.println( "Usage:" );
137 System.out.println();
138 System.out.println( PRG_NAME + " <pfam2go file> <file with pfams>" );
139 System.out.println();
140 System.out.println();