final SortedSet<String> not_found = new TreeSet<String>();
for( final PhylogenyNodeIterator iter = phy.iteratorPostorder(); iter.hasNext(); ) {
final PhylogenyNode node = iter.next();
- // final QUERY_TYPE qt = null;
- // Taxonomy tax = null;
- // if ( node.getNodeData().isHasTaxonomy() ) {
- // tax = node.getNodeData().getTaxonomy();
- // }
- // UniProtTaxonomy up_tax = null;
- // if ( ( tax != null )
- // && ( isHasAppropriateId( tax ) || !ForesterUtil.isEmpty(
- // tax.getScientificName() )
- // || !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ||
- // !ForesterUtil.isEmpty( tax
- // .getCommonName() ) ) ) {
- // final String query = null;
- // up_tax = obtainUniProtTaxonomy( tax, query, qt );
- // if ( up_tax == null ) {
- // not_found.add( query );
- // }
- // else {
- // updateTaxonomy( qt, node, tax, up_tax );
- // }
- // }
if ( !node.isExternal() ) {
inferTaxonomyFromDescendents( node, not_found );
}
final UniProtTaxonomy up_tax = obtainUniProtTaxonomy( desc.getNodeData().getTaxonomy(), query, qt );
String[] lineage = null;
if ( up_tax != null ) {
- lineage = obtainLineagePlusOwnScientificName( up_tax );
+ //lineage = obtainLineagePlusOwnScientificName( up_tax );
+ lineage = up_tax.getLineageAsArray();
}
if ( ( lineage == null ) || ( lineage.length < 1 ) ) {
+ //TODO remove me
+ System.out.println( "node " + desc.getNodeData().getTaxonomy().toString() + " has no lineage!" );
not_found.add( desc.getNodeData().getTaxonomy().asText().toString() );
return;
}
}
else {
String msg = "Node(s) with no or inappropriate taxonomic information found";
+ String node = "";
if ( !ForesterUtil.isEmpty( desc.getName() ) ) {
- msg = "Node " + desc.getName() + " has no or inappropriate taxonomic information";
+ node = "\"" + desc.getName() + "\"";
}
+ else {
+ node = "[" + desc.getId() + "]";
+ }
+ msg = "Node " + node + " has no or inappropriate taxonomic information";
+ List<PhylogenyNode> e = desc.getAllExternalDescendants();
+ //TODO remove me!
+ System.out.println();
+ int x = 0;
+ for( PhylogenyNode object : e ) {
+ System.out.println( x + ":" );
+ System.out.println( object.getName() + " " );
+ x++;
+ }
+ System.out.println();
+ //
throw new IllegalArgumentException( msg );
}
}
}
}
if ( last_common_lineage == null ) {
+ System.out.println( "No common lineage for:" );
+ int counter = 0;
+ for( String[] strings : lineages ) {
+ System.out.print( counter + ": " );
+ ++counter;
+ for( String string : strings ) {
+ System.out.print( string + " " );
+ }
+ System.out.println();
+ }
return;
}
// if ( !n.getNodeData().isHasTaxonomy() ) {
return not_found;
}
- synchronized private static String[] obtainLineagePlusOwnScientificName( final UniProtTaxonomy up_tax ) {
- final String[] lineage = up_tax.getLineage();
- final String[] lin_plus_self = new String[ lineage.length + 1 ];
- for( int i = 0; i < lineage.length; ++i ) {
- lin_plus_self[ i ] = lineage[ i ];
- }
- lin_plus_self[ lineage.length ] = up_tax.getScientificName();
- return lin_plus_self;
- }
-
+ // TODO this might not be needed anymore
+ // synchronized private static String[] obtainLineagePlusOwnScientificName( final UniProtTaxonomy up_tax ) {
+ // final String[] lineage = up_tax.getLineageAsArray();
+ // final String[] lin_plus_self = new String[ lineage.length + 1 ];
+ // for( int i = 0; i < lineage.length; ++i ) {
+ // lin_plus_self[ i ] = lineage[ i ];
+ // }
+ // lin_plus_self[ lineage.length ] = up_tax.getScientificName();
+ // return lin_plus_self;
+ // }
synchronized private static UniProtTaxonomy obtainUniProtTaxonomy( final Taxonomy tax, String query, QUERY_TYPE qt )
throws IOException {
if ( isHasAppropriateId( tax ) ) {
_obtain_detailed_taxonomic_information_jmi
.setToolTipText( "To add additional taxonomic information (from UniProt Taxonomy)" );
_tools_menu
- .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (Delete Nodes)" ) );
+ .add( _obtain_detailed_taxonomic_information_deleting_jmi = new JMenuItem( "Obtain Detailed Taxonomic Information (deletes nodes!)" ) );
customizeJMenuItem( _obtain_detailed_taxonomic_information_deleting_jmi );
_obtain_detailed_taxonomic_information_deleting_jmi
.setToolTipText( "To add additional taxonomic information, deletes nodes for which taxonomy cannot found (from UniProt Taxonomy)" );
JOptionPane.ERROR_MESSAGE );
return;
}
- final Phylogeny phy = _mainpanel.getCurrentPhylogeny().copy();
final AncestralTaxonomyInferrer inferrer = new AncestralTaxonomyInferrer( this,
_mainpanel.getCurrentTreePanel(),
- phy );
+ _mainpanel.getCurrentPhylogeny()
+ .copy() );
new Thread( inferrer ).start();
}
import java.util.Set;
import org.forester.application.support_transfer;
-import org.forester.archaeopteryx.Archaeopteryx;
import org.forester.development.DevelopmentTools;
import org.forester.evoinference.TestPhylogenyReconstruction;
import org.forester.evoinference.matrix.character.CharacterStateMatrix;
if ( !results.get( 0 ).getScientificName().equals( "Nematostella vectensis" ) ) {
return false;
}
- if ( !results.get( 0 ).getLineage()[ 0 ].equals( "Eukaryota" ) ) {
+ if ( !results.get( 0 ).getLineage().get( 1 ).equals( "Eukaryota" ) ) {
return false;
}
- if ( !results.get( 0 ).getLineage()[ 1 ].equals( "Metazoa" ) ) {
+ if ( !results.get( 0 ).getLineage().get( 2 ).equals( "Metazoa" ) ) {
return false;
}
- if ( !results.get( 0 ).getLineage()[ results.get( 0 ).getLineage().length - 1 ].equals( "Nematostella" ) ) {
+ if ( !results.get( 0 ).getLineage().get( results.get( 0 ).getLineage().size() - 1 )
+ .equals( "Nematostella vectensis" ) ) {
+ System.out.println( results.get( 0 ).getLineage() );
return false;
}
}
public final class UniProtTaxonomy {
- private final String[] _lineage;
+ private static final String ARCHAEA = "Archaea";
+ private static final String BACTERIA = "Bacteria";
+ private static final String EUKARYOTA = "Eukaryota";
+ private final List<String> _lineage;
private final String _code;
private final String _scientific_name;
private final String _common_name;
private final String _synonym;
private final String _rank;
private final String _id;
- public final static UniProtTaxonomy DROSOPHILA_GENUS = new UniProtTaxonomy( new String[] { "Eukaryota",
- "Metazoa", "Arthropoda", "Hexapoda", "Insecta", "Pterygota", "Neoptera", "Endopterygota", "Diptera",
- "Brachycera", "Muscomorpha", "Ephydroidea", "Drosophilidae" },
+ public final static String CELLULAR_ORGANISMS = "cellular organisms";
+ public final static UniProtTaxonomy DROSOPHILA_GENUS = new UniProtTaxonomy( new String[] {
+ CELLULAR_ORGANISMS, EUKARYOTA, "Metazoa", "Arthropoda", "Hexapoda", "Insecta", "Pterygota", "Neoptera",
+ "Endopterygota", "Diptera", "Brachycera", "Muscomorpha", "Ephydroidea", "Drosophilidae" },
"",
"fruit flies",
"Drosophila",
"",
"genus",
"7215" );
- public final static UniProtTaxonomy XENOPUS_GENUS = new UniProtTaxonomy( new String[] { "Eukaryota",
- "Metazoa", "Chordata", "Craniata", "Vertebrata", "Euteleostomi", "Amphibia", "Batrachia", "Anura",
- "Mesobatrachia", "Pipoidea", "Pipidae", "Xenopodinae" }, "", "", "Xenopus", "", "genus", "8353" );
- public final static UniProtTaxonomy CAPITELLA_TELATA_SPECIES = new UniProtTaxonomy( new String[] { "Eukaryota",
- "Metazoa", "Annelida", "Polychaeta", "Scolecida", "Capitellida", "Capitellidae", "Capitella" },
+ public final static UniProtTaxonomy XENOPUS_GENUS = new UniProtTaxonomy( new String[] {
+ CELLULAR_ORGANISMS, EUKARYOTA, "Metazoa", "Chordata", "Craniata", "Vertebrata", "Euteleostomi", "Amphibia",
+ "Batrachia", "Anura", "Mesobatrachia", "Pipoidea", "Pipidae", "Xenopodinae" },
+ "",
+ "",
+ "Xenopus",
+ "",
+ "genus",
+ "8353" );
+ public final static UniProtTaxonomy CAPITELLA_TELATA_SPECIES = new UniProtTaxonomy( new String[] {
+ CELLULAR_ORGANISMS, EUKARYOTA, "Metazoa", "Annelida", "Polychaeta", "Scolecida", "Capitellida",
+ "Capitellidae", "Capitella" },
"",
"",
"Capitella teleta",
if ( items.length > 7 ) {
lin = items[ 8 ].split( "; " );
}
+ _lineage = new ArrayList<String>();
if ( ( lin != null ) && ( lin.length > 0 ) ) {
final List<String> temp = new ArrayList<String>();
for( final String t : lin ) {
temp.add( t.trim() );
}
}
- _lineage = new String[ temp.size() ];
for( int i = 0; i < temp.size(); ++i ) {
- _lineage[ i ] = temp.get( i );
+ if ( i == 0
+ && ( temp.get( i ).equalsIgnoreCase( EUKARYOTA ) || temp.get( i ).equalsIgnoreCase( BACTERIA ) || temp
+ .get( i ).equalsIgnoreCase( ARCHAEA ) ) ) {
+ _lineage.add( CELLULAR_ORGANISMS );
+ }
+ _lineage.add( temp.get( i ) );
}
}
- else {
- _lineage = new String[ 0 ];
+ if ( _lineage.isEmpty()
+ && ( _scientific_name.equalsIgnoreCase( EUKARYOTA ) || _scientific_name.equalsIgnoreCase( BACTERIA ) || _scientific_name
+ .equalsIgnoreCase( ARCHAEA ) ) ) {
+ System.out.println( " >>>>>>>>>>>>>>>>>>>>>>>>> did it!" );
+ _lineage.add( CELLULAR_ORGANISMS );
+ }
+ _lineage.add( _scientific_name );
+ if ( _lineage.isEmpty() ) {
+ throw new IllegalArgumentException( "lineage in a UniProt Taxonomy can not be empty\n: " + line );
}
}
- public UniProtTaxonomy( final String[] lineage,
+ public UniProtTaxonomy( final List<String> lineage,
final String code,
final String common_name,
final String scientific_name,
_id = id;
}
+ public UniProtTaxonomy( final String[] lineage,
+ final String code,
+ final String common_name,
+ final String scientific_name,
+ final String synonym,
+ final String rank,
+ final String id ) {
+ _lineage = new ArrayList<String>();
+ for( String l : lineage ) {
+ _lineage.add( l );
+ }
+ _code = code;
+ _scientific_name = scientific_name;
+ _common_name = common_name;
+ _synonym = synonym;
+ _rank = rank;
+ _id = id;
+ }
+
/**
* Creates deep copy for all fields, except lineage.
*
return _id;
}
- public String[] getLineage() {
+ public List<String> getLineage() {
return _lineage;
}
+ public String[] getLineageAsArray() {
+ String[] str = new String[ _lineage.size() ];
+ int i = 0;
+ for( String l : _lineage ) {
+ str[ i++ ] = l;
+ }
+ return str;
+ }
+
public String getRank() {
return _rank;
}
// Ignore empty lines.
}
else if ( line.startsWith( "Taxon" ) ) {
- //TODO next the check format FIXME
+ final String[] items = line.split( "\t" );
+ if ( !( items[ 1 ].equalsIgnoreCase( "Mnemonic" ) && items[ 2 ].equalsIgnoreCase( "Scientific name" )
+ && items[ 3 ].equalsIgnoreCase( "Common name" ) && items[ 4 ].equalsIgnoreCase( "Synonym" )
+ && items[ 5 ].equalsIgnoreCase( "Other Names" ) && items[ 6 ].equalsIgnoreCase( "Reviewed" )
+ && items[ 7 ].equalsIgnoreCase( "Rank" ) && items[ 8 ].equalsIgnoreCase( "Lineage" ) ) ) {
+ throw new IOException( "Unreconized UniProt Taxonomy format: " + line );
+ }
}
else {
if ( line.split( "\t" ).length > 4 ) {
String line;
final List<String> result = new ArrayList<String>();
while ( ( line = in.readLine() ) != null ) {
- System.out.println( line );
+ if ( DEBUG ) {
+ System.out.println( line );
+ }
result.add( line );
if ( result.size() > max_lines_to_return ) {
break;