3 // forester -- software libraries and applications
4 // for genomics and evolutionary biology research.
6 // Copyright (C) 2010 Christian M Zmasek
7 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.application;
29 import java.io.BufferedReader;
30 import java.io.FileNotFoundException;
31 import java.io.FileReader;
32 import java.util.HashMap;
35 public class pfamacc2pfamid {
37 final static private String PRG_NAME = "pfamacc2pfamid";
39 public static void main( final String args[] ) {
40 if ( args.length != 2 ) {
44 BufferedReader br = null;
46 br = new BufferedReader( new FileReader( args[ 0 ] ) );
48 catch ( final FileNotFoundException e ) {
53 final Map<String, String> acc_id = new HashMap<String, String>();
56 while ( ( line = br.readLine() ) != null ) {
57 if ( line.startsWith( "#=GF ID" ) ) {
59 System.err.println( "illegal format" );
62 id = line.substring( 7 ).trim();
64 else if ( line.startsWith( "#=GF AC" ) ) {
66 System.err.println( "illegal format" );
69 String acc = line.substring( 7 ).trim();
70 if ( acc.indexOf( '.' ) > 0 ) {
71 acc = acc.substring( 0, acc.indexOf( '.' ) );
73 acc_id.put( acc, id );
76 else if ( line.startsWith( "//" ) ) {
78 System.err.println( "illegal format" );
84 catch ( final Exception e ) {
89 br = new BufferedReader( new FileReader( args[ 1 ] ) );
91 catch ( final FileNotFoundException e ) {
97 while ( ( line = br.readLine() ) != null ) {
99 if ( ( line.length() > 0 ) && !line.startsWith( "#" ) ) {
100 String[] pfam_accs = null;
101 if ( line.contains( "," ) ) {
102 pfam_accs = line.split( "," );
105 pfam_accs = new String[ 1 ];
106 pfam_accs[ 0 ] = line;
108 for( final String pfam_acc : pfam_accs ) {
109 if ( acc_id.containsKey( pfam_acc ) ) {
110 System.out.println( acc_id.get( pfam_acc ) );
119 catch ( final Exception e ) {
123 System.err.println( "# not found: " + not_found );
126 private static void printHelp() {
127 System.out.println();
128 System.out.println( PRG_NAME + " <Pfam full> <file with pfam accessors, newline and/or comma separated>" );
129 System.out.println();