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.IOException;
35 import java.util.ArrayList;
36 import java.util.List;
38 import org.forester.io.writers.SequenceWriter;
39 import org.forester.io.writers.SequenceWriter.SEQ_FORMAT;
40 import org.forester.sequence.BasicSequence;
41 import org.forester.sequence.MolecularSequence;
42 import org.forester.util.BasicTable;
43 import org.forester.util.BasicTableParser;
44 import org.forester.util.CommandLineArguments;
45 import org.forester.util.ForesterUtil;
47 public final class table2fasta {
49 final static private String PRG_NAME = "table2fasta";
50 final static private String PRG_VERSION = "1.00";
51 final static private String PRG_DATE = "150327";
53 public static void main( final String args[] ) {
54 ForesterUtil.printProgramInformation( table2fasta.PRG_NAME, table2fasta.PRG_VERSION, table2fasta.PRG_DATE );
56 if ( ( args.length != 3 ) ) {
57 table2fasta.argumentsError();
59 CommandLineArguments cla = null;
61 cla = new CommandLineArguments( args );
63 catch ( final Exception e ) {
64 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
66 final int position = Integer.parseInt( cla.getName( 0 ) );
67 final File intable = cla.getFile( 1 );
68 final File outfile = cla.getFile( 2 );
69 BasicTable<String> t = null;
71 t = BasicTableParser.parse( intable, '\t' );
73 catch ( final IOException e ) {
76 final List<MolecularSequence> seqs = new ArrayList<MolecularSequence>();
77 for( int r = 0; r < t.getNumberOfRows(); ++r ) {
79 final StringBuilder id = new StringBuilder();
80 for( int c = 0; c < t.getNumberOfColumns(); ++c ) {
81 if ( c == position ) {
82 seq = t.getValue( c, r );
85 id.append( t.getValue( c, r ) );
89 final MolecularSequence s = BasicSequence.createDnaSequence( id.toString().trim(), seq );
93 SequenceWriter.writeSeqs( seqs, outfile, SEQ_FORMAT.FASTA, 6 );
95 catch ( final IOException e ) {
100 private static void argumentsError() {
101 System.out.println( PRG_NAME + " <position> <infile> <outfile>" );
102 System.out.println();