in progress...
[jalview.git] / forester / java / src / org / forester / application / rename_fasta.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
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.
13 //
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.
18 //
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
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25 //
26 //
27 // "java -Xmx1024m -cp path\to\forester.jar org.forester.application.fasta_split
28 //
29 //
30
31 package org.forester.application;
32
33 import java.io.File;
34 import java.io.FileInputStream;
35 import java.io.FileNotFoundException;
36 import java.io.IOException;
37 import java.util.ArrayList;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41 import java.util.regex.Matcher;
42 import java.util.regex.Pattern;
43
44 import org.forester.io.parsers.FastaParser;
45 import org.forester.io.writers.SequenceWriter;
46 import org.forester.io.writers.SequenceWriter.SEQ_FORMAT;
47 import org.forester.sequence.BasicSequence;
48 import org.forester.sequence.MolecularSequence;
49 import org.forester.util.CommandLineArguments;
50 import org.forester.util.ForesterUtil;
51
52 public final class rename_fasta {
53
54     
55
56     public static void main( final String args[] ) {
57         try {
58             final File infile = new File( args[ 0 ] );
59             final File outfile = new File( args[ 1 ] );
60             List<MolecularSequence> seqs;
61             seqs = FastaParser.parse( new FileInputStream( infile ) );
62             for( MolecularSequence seq : seqs ) {
63                 BasicSequence bseq = ( BasicSequence ) seq;
64                 final int i = bseq.getIdentifier().lastIndexOf( '_' );
65                 if ( i > 0 ) {
66                     bseq.setIdentifier( bseq.getIdentifier().substring( i + 1 ) );
67                 }
68             }
69             SequenceWriter.writeSeqs( seqs, outfile, SEQ_FORMAT.FASTA, 60 );
70         }
71         catch ( FileNotFoundException e ) {
72             e.printStackTrace();
73         }
74         catch ( IOException e ) {
75             e.printStackTrace();
76         }
77     }
78
79   
80 }