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: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.application;
29 import java.io.IOException;
30 import java.util.List;
33 import java.util.SortedSet;
34 import java.util.TreeSet;
36 import org.forester.go.GoId;
37 import org.forester.go.GoTerm;
38 import org.forester.go.GoUtils;
39 import org.forester.go.OBOparser;
40 import org.forester.go.PfamToGoMapping;
41 import org.forester.go.PfamToGoParser;
43 public class pfam2go_extractor {
45 final static private String PRG_NAME = "pfam2go_extractor";
47 public static void main( final String args[] ) {
48 if ( args.length < 3 ) {
51 final PfamToGoParser p = new PfamToGoParser( new File( args[ 0 ] ) );
52 List<PfamToGoMapping> pfam2go = null;
56 catch ( final IOException e ) {
60 final OBOparser parser = new OBOparser( new File( args[ 1 ] ), OBOparser.ReturnType.BASIC_GO_TERM );
61 List<GoTerm> all_go_terms = null;
63 all_go_terms = parser.parse();
65 catch ( final IOException e ) {
69 final Map<GoId, GoTerm> goid_to_term_map = GoUtils.createGoIdToGoTermMap( all_go_terms );
70 System.out.println( "# pfam2go : " + args[ 0 ] );
71 System.out.println( "# OBO file: " + args[ 1 ] );
72 final GoId[] queries = new GoId[ args.length - 2 ];
73 for( int i = 2; i < args.length; ++i ) {
74 queries[ i - 2 ] = new GoId( args[ i ] );
75 System.out.println( "# " + ( i - 2 ) + ": " + queries[ i - 2 ].getId() + " = "
76 + goid_to_term_map.get( queries[ i - 2 ] ).getName() + " ("
77 + goid_to_term_map.get( queries[ i - 2 ] ).getDefinition() + ")" );
79 final SortedSet<String> pfams = new TreeSet<String>();
80 for( final PfamToGoMapping pfam_to_go_mapping : pfam2go ) {
81 final String domain_id = pfam_to_go_mapping.getKey();
82 final GoId go_id = pfam_to_go_mapping.getValue();
83 final Set<GoId> supers = GoUtils.getAllSuperGoIds( go_id, goid_to_term_map );
85 for( final GoId querie : queries ) {
86 if ( supers.contains( querie ) ) {
87 pfams.add( domain_id.toString() );
91 for( final String pfam : pfams ) {
92 System.out.println( pfam );
96 private static void printHelp() {
98 System.out.println( PRG_NAME
99 + " <pfam2go mapping file> <file with all GO terms, in 'obo' format> <GO id> [more GO ids]" );
100 System.out.println();