2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-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
27 // "java -Xmx1024m -cp path\to\forester.jar org.forester.application.fasta_split
31 package org.forester.application;
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;
41 import java.util.regex.Matcher;
42 import java.util.regex.Pattern;
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;
52 public final class rename_fasta {
56 public static void main( final String args[] ) {
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( '_' );
66 bseq.setIdentifier( bseq.getIdentifier().substring( i + 1 ) );
69 SequenceWriter.writeSeqs( seqs, outfile, SEQ_FORMAT.FASTA, 60 );
71 catch ( FileNotFoundException e ) {
74 catch ( IOException e ) {