// Copyright (C) 2009 Christian M. Zmasek
// Copyright (C) 2009 Burnham Institute for Medical Research
// All rights reserved
-//
+//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
-//
+//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
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;
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<PfamToGoMapping> mappings ) throws IOException {
+ private static void process( final File pfams_file,
+ final List<PfamToGoMapping> 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<String> encountered_domains = new HashSet<String>();
+ Collection<String> encountered_domains = null;
+ if ( allow_duplicates ) {
+ encountered_domains = new ArrayList<String>();
+ }
+ else {
+ encountered_domains = new HashSet<String>();
+ }
while ( ( line = reader.readLine() ) != null ) {
line = line.trim();
if ( ForesterUtil.isEmpty( line ) || line.startsWith( "##" ) ) {
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 ) {
System.exit( 0 );
}
final List<String> allowed_options = new ArrayList<String>();
- if ( cla.getNumberOfNames() != 2 ) {
+ allowed_options.add( ALLOW_DUPLICATES_OPTION );
+ if ( ( cla.getNumberOfNames() != 2 ) && ( cla.getNumberOfNames() != 3 ) ) {
printHelp();
System.exit( -1 );
}
}
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<PfamToGoMapping> mappings = null;
try {
e.printStackTrace();
}
try {
- doit( pfams_file, mappings );
+ process( pfams_file, mappings, allow_duplicates );
}
catch ( final IOException e ) {
e.printStackTrace();
ForesterUtil.printProgramInformation( PRG_NAME, PRG_VERSION, PRG_DATE, E_MAIL, WWW );
System.out.println( "Usage:" );
System.out.println();
- System.out.println( PRG_NAME + " <pfam2go file> <file with pfams>" );
+ System.out.println( PRG_NAME + " [-" + ALLOW_DUPLICATES_OPTION
+ + " to allow duplicates] <pfam2go file> <file with pfams>" );
System.out.println();
System.out.println();
}