X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fapplication%2Fpfam_go.java;h=df679e175607780564c45217825a566f416861d5;hb=f7f0102d3e7eb2fd254f7d22d75a88495133449c;hp=194def26987e867958c1e06257239049ea66db2a;hpb=eee996a6476a1e3d84c07f8f690dcde3ff4b2ef5;p=jalview.git diff --git a/forester/java/src/org/forester/application/pfam_go.java b/forester/java/src/org/forester/application/pfam_go.java index 194def2..df679e1 100644 --- a/forester/java/src/org/forester/application/pfam_go.java +++ b/forester/java/src/org/forester/application/pfam_go.java @@ -21,7 +21,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.application; @@ -29,9 +29,9 @@ import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Set; import org.forester.go.PfamToGoMapping; import org.forester.go.PfamToGoParser; @@ -40,20 +40,29 @@ import org.forester.util.ForesterUtil; public class pfam_go { - final static private String HELP_OPTION_1 = "help"; - final static private String HELP_OPTION_2 = "h"; - final static private String PRG_NAME = "pfam2go"; - final static private String PRG_VERSION = "1.00"; - final static private String PRG_DATE = "2010.02.02"; - final static private String E_MAIL = "czmasek@burnham.org"; - final static private String WWW = "www.phylosoft.org"; + private static final String ALLOW_DUPLICATES_OPTION = "d"; + final static private String HELP_OPTION_1 = "help"; + final static private String HELP_OPTION_2 = "h"; + final static private String PRG_NAME = "pfam_go"; + final static private String PRG_VERSION = "1.10"; + final static private String PRG_DATE = "2011.06.26"; + final static private String E_MAIL = "czmasek@burnham.org"; + final static private String WWW = "www.phylosoft.org"; - private static void doit( final File pfams_file, final List mappings ) throws IOException { + private static void process( final File pfams_file, + final List mappings, + final boolean allow_duplicates ) throws IOException { final BufferedReader reader = ForesterUtil.obtainReader( pfams_file ); String line = ""; int found_count = 0; int not_found_count = 0; - final Set encountered_domains = new HashSet(); + Collection encountered_domains = null; + if ( allow_duplicates ) { + encountered_domains = new ArrayList(); + } + else { + encountered_domains = new HashSet(); + } while ( ( line = reader.readLine() ) != null ) { line = line.trim(); if ( ForesterUtil.isEmpty( line ) || line.startsWith( "##" ) ) { @@ -65,11 +74,11 @@ public class pfam_go { System.out.println( line ); } else { - if ( !encountered_domains.contains( line ) ) { + if ( allow_duplicates || !encountered_domains.contains( line ) ) { encountered_domains.add( line ); boolean found = false; for( final PfamToGoMapping mapping : mappings ) { - if ( mapping.getKey().getId().equals( line ) ) { + if ( mapping.getKey().equals( line ) ) { System.out.println( mapping.getValue() ); found = true; } @@ -104,7 +113,8 @@ public class pfam_go { System.exit( 0 ); } final List allowed_options = new ArrayList(); - if ( cla.getNumberOfNames() != 2 ) { + allowed_options.add( ALLOW_DUPLICATES_OPTION ); + if ( ( cla.getNumberOfNames() != 2 ) && ( cla.getNumberOfNames() != 3 ) ) { printHelp(); System.exit( -1 ); } @@ -114,6 +124,10 @@ public class pfam_go { } final File pfam2go_file = cla.getFile( 0 ); final File pfams_file = cla.getFile( 1 ); + boolean allow_duplicates = false; + if ( cla.isOptionSet( ALLOW_DUPLICATES_OPTION ) ) { + allow_duplicates = true; + } final PfamToGoParser pfam2go_parser = new PfamToGoParser( pfam2go_file ); List mappings = null; try { @@ -123,7 +137,7 @@ public class pfam_go { e.printStackTrace(); } try { - doit( pfams_file, mappings ); + process( pfams_file, mappings, allow_duplicates ); } catch ( final IOException e ) { e.printStackTrace(); @@ -135,7 +149,8 @@ public class pfam_go { ForesterUtil.printProgramInformation( PRG_NAME, PRG_VERSION, PRG_DATE, E_MAIL, WWW ); System.out.println( "Usage:" ); System.out.println(); - System.out.println( PRG_NAME + " " ); + System.out.println( PRG_NAME + " [-" + ALLOW_DUPLICATES_OPTION + + " to allow duplicates] " ); System.out.println(); System.out.println(); }