3 // forester -- software libraries and applications
4 // for genomics and evolutionary biology research.
6 // Copyright (C) 2011 Christian M Zmasek
7 // Copyright (C) 2011 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: www.phylosoft.org/forester
27 package org.forester.applications;
30 import java.io.IOException;
31 import java.util.List;
33 import org.forester.archaeopteryx.Archaeopteryx;
34 import org.forester.io.parsers.FastaParser;
35 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
36 import org.forester.phylogeny.Phylogeny;
37 import org.forester.phylogeny.PhylogenyNode;
38 import org.forester.phylogeny.data.PropertiesMap;
39 import org.forester.phylogeny.data.Property;
40 import org.forester.phylogeny.data.Property.AppliesTo;
41 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
42 import org.forester.phylogeny.factories.PhylogenyFactory;
43 import org.forester.sequence.MolecularSequence;
44 import org.forester.util.CommandLineArguments;
45 import org.forester.util.ForesterUtil;
47 public class map_lengths {
49 final static private String PRG_NAME = "map_lengths";
51 public static void main( final String[] args ) {
52 CommandLineArguments cla = null;
54 cla = new CommandLineArguments( args );
56 catch ( final Exception e ) {
57 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
60 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
61 final PhyloXmlParser xml_parser = PhyloXmlParser.createPhyloXmlParserXsdValidating();
63 final Phylogeny[] phylogenies_0 = factory.create( cla.getFile( 0 ), xml_parser );
64 final Phylogeny phy = phylogenies_0[ 0 ];
65 for( int i = 1; i < cla.getNumberOfNames(); i++ ) {
66 final String fasta_name = cla.getName( i );
67 final List<MolecularSequence> seqs = FastaParser.parse( new File( fasta_name ) );
68 for( int s = 0; s < seqs.size(); s++ ) {
69 final MolecularSequence seq = seqs.get( s );
70 final int actual_length = seq.getLength() - seq.getNumberOfGapResidues();
71 String node_name = "" + seq.getIdentifier();
72 node_name = node_name.substring( 0, node_name.indexOf( "/" ) );
73 final PhylogenyNode n = phy.getNode( node_name );
74 if ( n.getNodeData().getProperties() == null ) {
75 n.getNodeData().setProperties( new PropertiesMap() );
77 final PropertiesMap properties = n.getNodeData().getProperties();
78 final Property p = new Property( "r:" + i, "" + actual_length, "", "xsd:integer", AppliesTo.NODE );
79 properties.addProperty( p );
82 Archaeopteryx.createApplication( phy );
84 catch ( final IOException e ) {
85 // TODO Auto-generated catch block