1 // javac -cp ~/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester/java/forester.jar
2 // ~/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester_applications/src/org/forester/applications/subtree_feature_count.java
5 // /home/czmasek/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester_applications/src/:/home/czmasek/SOFTWARE_DEV/ECLIPSE_WORKSPACE/forester/java/forester.jar
6 // org.forester.applications.subtree_feature_count
8 package org.forester.applications;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.SortedSet;
15 import org.forester.io.parsers.phyloxml.PhyloXmlParser;
16 import org.forester.phylogeny.Phylogeny;
17 import org.forester.phylogeny.PhylogenyMethods;
18 import org.forester.phylogeny.PhylogenyNode;
19 import org.forester.phylogeny.data.Accession;
20 import org.forester.phylogeny.data.Sequence;
21 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
22 import org.forester.phylogeny.factories.PhylogenyFactory;
23 import org.forester.util.CommandLineArguments;
24 import org.forester.util.ForesterUtil;
26 public class subtree_feature_count {
28 final static private String MIN_DISTANCE_TO_ROOT_OPTION = "d";
29 final static private String E_MAIL = "phylosoft@gmail.com";
30 final static private String HELP_OPTION_1 = "help";
31 final static private String HELP_OPTION_2 = "h";
32 final static private String PRG_DATE = "131120";
33 final static private String PRG_DESC = "";
34 final static private String PRG_NAME = "subtree_feature_count";
35 final static private String PRG_VERSION = "0.90";
36 final static private String WWW = "sites.google.com/site/cmzmasek/home/software/forester";
38 public static void main( final String args[] ) {
40 final CommandLineArguments cla = new CommandLineArguments( args );
41 if ( cla.isOptionSet( HELP_OPTION_1 ) || cla.isOptionSet( HELP_OPTION_2 ) || ( args.length < 2 ) ) {
45 final List<String> allowed_options = new ArrayList<String>();
46 allowed_options.add( MIN_DISTANCE_TO_ROOT_OPTION );
47 final String dissallowed_options = cla.validateAllowedOptionsAsString( allowed_options );
48 if ( dissallowed_options.length() > 0 ) {
49 ForesterUtil.fatalError( PRG_NAME, "unknown option(s): " + dissallowed_options );
51 final double min_distance_to_root = cla.getOptionValueAsDouble( MIN_DISTANCE_TO_ROOT_OPTION );
52 if ( min_distance_to_root <= 0 ) {
53 ForesterUtil.fatalError( PRG_NAME, "attempt to use min distance to root of: " + min_distance_to_root );
55 final File intree_file = cla.getFile( 0 );
56 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
57 final Phylogeny phy = factory.create( intree_file, PhyloXmlParser.createPhyloXmlParserXsdValidating() )[ 0 ];
58 execute( phy, min_distance_to_root );
60 catch ( final Exception e ) {
62 ForesterUtil.fatalError( PRG_NAME, e.getMessage() );
66 private final static void execute( final Phylogeny phy, final double min_distance_to_root ) {
67 final List<List<PhylogenyNode>> ll = PhylogenyMethods.divideIntoSubTrees( phy, min_distance_to_root );
68 for( final List<PhylogenyNode> l : ll ) {
72 for( final PhylogenyNode node : l ) {
73 if ( node.getNodeData().isHasSequence() ) {
74 final Sequence seq = node.getNodeData().getSequence();
75 final SortedSet<Accession> xrefs = seq.getCrossReferences();
76 if ( !ForesterUtil.isEmpty( xrefs ) ) {
77 for( final Accession xref : xrefs ) {
78 if ( xref.getSource().equalsIgnoreCase( "pdb" ) ) {
79 if ( xref.getComment().equalsIgnoreCase( "x-ray" )
80 || xref.getComment().equalsIgnoreCase( "xray" ) ) {
83 if ( xref.getComment().equalsIgnoreCase( "nmr" ) ) {
86 if ( xref.getComment().equalsIgnoreCase( "model" ) ) {
94 final int n = l.size();
95 final double xray_p = ForesterUtil.round( ( 100.0 * xray ) / n, 1 );
96 final double nmr_p = ForesterUtil.round( ( 100.0 * nmr ) / n, 1 );
97 final double model_p = ForesterUtil.round( ( 100.0 * model ) / n, 1 );
98 final StringBuilder sb = new StringBuilder();
99 sb.append( String.valueOf( n ) );
101 sb.append( String.valueOf( xray ) );
103 sb.append( String.valueOf( nmr ) );
105 sb.append( String.valueOf( model ) );
107 sb.append( String.valueOf( xray_p ) );
109 sb.append( String.valueOf( nmr_p ) );
111 sb.append( String.valueOf( model_p ) );
112 System.out.println( sb );
116 private static void printHelp() {
117 ForesterUtil.printProgramInformation( PRG_NAME,
123 ForesterUtil.getForesterLibraryInformation() );
124 System.out.print( "Usage: " );
125 System.out.println( PRG_NAME + " -d=<min distance to root> <intree>" );
126 System.out.println();
127 System.out.println();