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;
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;
42 import org.forester.protein.DomainId;
44 public class pfam2go_extractor {
46 final static private String PRG_NAME = "pfam2go_extractor";
48 public static void main( final String args[] ) {
49 if ( args.length < 3 ) {
52 final PfamToGoParser p = new PfamToGoParser( new File( args[ 0 ] ) );
53 List<PfamToGoMapping> pfam2go = null;
57 catch ( final IOException e ) {
61 final OBOparser parser = new OBOparser( new File( args[ 1 ] ), OBOparser.ReturnType.BASIC_GO_TERM );
62 List<GoTerm> all_go_terms = null;
64 all_go_terms = parser.parse();
66 catch ( final IOException e ) {
70 final Map<GoId, GoTerm> goid_to_term_map = GoUtils.createGoIdToGoTermMap( all_go_terms );
71 System.out.println( "# pfam2go : " + args[ 0 ] );
72 System.out.println( "# OBO file: " + args[ 1 ] );
73 final GoId[] queries = new GoId[ args.length - 2 ];
74 for( int i = 2; i < args.length; ++i ) {
75 queries[ i - 2 ] = new GoId( args[ i ] );
76 System.out.println( "# " + ( i - 2 ) + ": " + queries[ i - 2 ].getId() + " = "
77 + goid_to_term_map.get( queries[ i - 2 ] ).getName() + " ("
78 + goid_to_term_map.get( queries[ i - 2 ] ).getDefinition() + ")" );
80 final SortedSet<String> pfams = new TreeSet<String>();
81 for( final PfamToGoMapping pfam_to_go_mapping : pfam2go ) {
82 final DomainId domain_id = pfam_to_go_mapping.getKey();
83 final GoId go_id = pfam_to_go_mapping.getValue();
84 final Set<GoId> supers = GoUtils.getAllSuperGoIds( go_id, goid_to_term_map );
86 for( int i = 0; i < queries.length; ++i ) {
87 if ( supers.contains( queries[ i ] ) ) {
88 pfams.add( domain_id.toString() );
92 for( final String pfam : pfams ) {
93 System.out.println( pfam );
97 private static void printHelp() {
99 System.out.println( PRG_NAME
100 + " <pfam2go mapping file> <file with all GO terms, in 'obo' format> <GO id> [more GO ids]" );
101 System.out.println();