+ }
+
+ public static List<Long> searchData( final String query,
+ final Phylogeny phy,
+ final boolean case_sensitive,
+ final boolean partial,
+ final boolean regex,
+ final boolean search_domains,
+ final double domains_confidence_threshold ) {
+ final List<Long> nodes = new ArrayList<Long>();
+ if ( phy.isEmpty() || ( query == null ) ) {
+ return nodes;
+ }
+ if ( ForesterUtil.isEmpty( query ) ) {
+ return nodes;
+ }
+ String my_query = query;
+ NDF ndf = null;
+ if ( ( my_query.length() > 2 ) && ( my_query.indexOf( ":" ) == 2 ) ) {
+ ndf = NDF.fromString( my_query );
+ if ( ndf != null ) {
+ my_query = my_query.substring( 3 );
+ }
+ }
+ for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
+ final PhylogenyNode node = iter.next();
+ boolean match = false;
+ if ( ( ( ndf == null ) || ( ndf == NDF.NodeName ) )
+ && match( node.getName(), my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCode ) ) && node.getNodeData().isHasTaxonomy()
+ && match( node.getNodeData().getTaxonomy().getTaxonomyCode(),
+ my_query,
+ case_sensitive,
+ partial,
+ regex ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCommonName ) ) && node.getNodeData().isHasTaxonomy()
+ && match( node.getNodeData().getTaxonomy().getCommonName(),
+ my_query,
+ case_sensitive,
+ partial,
+ regex ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyScientificName ) ) && node.getNodeData().isHasTaxonomy()
+ && match( node.getNodeData().getTaxonomy().getScientificName(),
+ my_query,
+ case_sensitive,
+ partial,
+ regex ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyIdentifier ) ) && node.getNodeData().isHasTaxonomy()
+ && ( node.getNodeData().getTaxonomy().getIdentifier() != null )
+ && match( node.getNodeData().getTaxonomy().getIdentifier().getValue(),
+ my_query,
+ case_sensitive,
+ partial,
+ regex ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomySynonym ) ) && node.getNodeData().isHasTaxonomy()
+ && !node.getNodeData().getTaxonomy().getSynonyms().isEmpty() ) {
+ final List<String> syns = node.getNodeData().getTaxonomy().getSynonyms();
+ I: for( final String syn : syns ) {
+ if ( match( syn, my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ break I;
+ }
+ }
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceName ) ) && node.getNodeData().isHasSequence()
+ && match( node.getNodeData().getSequence().getName(), my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.GeneName ) ) && node.getNodeData().isHasSequence()
+ && match( node.getNodeData().getSequence().getGeneName(),
+ my_query,
+ case_sensitive,
+ partial,
+ regex ) ) {
+ match = true;
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceSymbol ) ) && node.getNodeData().isHasSequence()
+ && match( node.getNodeData().getSequence().getSymbol(),
+ my_query,
+ case_sensitive,
+ partial,
+ regex ) ) {
+ match = true;
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceAccession ) ) && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getAccession() != null )
+ && match( node.getNodeData().getSequence().getAccession().getValue(),
+ my_query,
+ case_sensitive,
+ partial,
+ regex ) ) {
+ match = true;
+ }
+ if ( !match && ( ( ( ndf == null ) && search_domains ) || ( ndf == NDF.Domain ) )
+ && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
+ final DomainArchitecture da = node.getNodeData().getSequence().getDomainArchitecture();
+ I: for( int i = 0; i < da.getNumberOfDomains(); ++i ) {
+ if ( ( da.getDomain( i ).getConfidence() <= domains_confidence_threshold )
+ && ( match( da.getDomain( i ).getName(), my_query, case_sensitive, partial, regex ) ) ) {
+ match = true;
+ break I;
+ }
+ }
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.Annotation ) ) && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getAnnotations() != null ) ) {
+ for( final Annotation ann : node.getNodeData().getSequence().getAnnotations() ) {
+ if ( match( ann.getDesc(), my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ break;
+ }
+ if ( match( ann.getRef(), my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ break;
+ }
+ }
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.CrossRef ) ) && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getCrossReferences() != null ) ) {
+ for( final Accession x : node.getNodeData().getSequence().getCrossReferences() ) {
+ if ( match( x.getComment(), my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ break;
+ }
+ if ( match( x.getSource(), my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ break;
+ }
+ if ( match( x.getValue(), my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ break;
+ }
+ }
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.BinaryCharacter ) )
+ && ( node.getNodeData().getBinaryCharacters() != null ) ) {
+ Iterator<String> it = node.getNodeData().getBinaryCharacters().getPresentCharacters().iterator();
+ I: while ( it.hasNext() ) {
+ if ( match( it.next(), my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ break I;
+ }
+ }
+ it = node.getNodeData().getBinaryCharacters().getGainedCharacters().iterator();
+ I: while ( it.hasNext() ) {
+ if ( match( it.next(), my_query, case_sensitive, partial, regex ) ) {
+ match = true;
+ break I;
+ }
+ }
+ }
+ if ( !match && ( ndf == NDF.MolecularSequence ) && node.getNodeData().isHasSequence()
+ && match( node.getNodeData().getSequence().getMolecularSequence(),
+ my_query,
+ case_sensitive,
+ true,
+ regex ) ) {
+ match = true;
+ }
+ if ( match ) {
+ nodes.add( node.getId() );
+ }
+ }
+ return nodes;
+ }
+
+ public static List<Long> searchDataLogicalAnd( final String[] queries,
+ final Phylogeny phy,
+ final boolean case_sensitive,
+ final boolean partial,
+ final boolean search_domains,
+ final double domains_confidence_threshold ) {
+ final List<Long> nodes = new ArrayList<Long>();
+ if ( phy.isEmpty() || ( queries == null ) || ( queries.length < 1 ) ) {
+ return nodes;
+ }
+ for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
+ final PhylogenyNode node = iter.next();
+ boolean all_matched = true;
+ for( String query : queries ) {
+ if ( query == null ) {
+ continue;
+ }
+ query = query.trim();
+ NDF ndf = null;
+ if ( ( query.length() > 2 ) && ( query.indexOf( ":" ) == 2 ) ) {
+ ndf = NDF.fromString( query );
+ if ( ndf != null ) {
+ query = query.substring( 3 );
+ }
+ }
+ boolean match = false;
+ if ( ForesterUtil.isEmpty( query ) ) {
+ continue;
+ }
+ if ( ( ( ndf == null ) || ( ndf == NDF.NodeName ) )
+ && match( node.getName(), query, case_sensitive, partial, false ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCode ) ) && node.getNodeData().isHasTaxonomy()
+ && match( node.getNodeData().getTaxonomy().getTaxonomyCode(),
+ query,
+ case_sensitive,
+ partial,
+ false ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyCommonName ) ) && node.getNodeData().isHasTaxonomy()
+ && match( node.getNodeData().getTaxonomy().getCommonName(),
+ query,
+ case_sensitive,
+ partial,
+ false ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyScientificName ) )
+ && node.getNodeData().isHasTaxonomy()
+ && match( node.getNodeData().getTaxonomy().getScientificName(),
+ query,
+ case_sensitive,
+ partial,
+ false ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomyIdentifier ) ) && node.getNodeData().isHasTaxonomy()
+ && ( node.getNodeData().getTaxonomy().getIdentifier() != null )
+ && match( node.getNodeData().getTaxonomy().getIdentifier().getValue(),
+ query,
+ case_sensitive,
+ partial,
+ false ) ) {
+ match = true;
+ }
+ else if ( ( ( ndf == null ) || ( ndf == NDF.TaxonomySynonym ) ) && node.getNodeData().isHasTaxonomy()
+ && !node.getNodeData().getTaxonomy().getSynonyms().isEmpty() ) {
+ final List<String> syns = node.getNodeData().getTaxonomy().getSynonyms();
+ I: for( final String syn : syns ) {
+ if ( match( syn, query, case_sensitive, partial, false ) ) {
+ match = true;
+ break I;
+ }
+ }
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceName ) ) && node.getNodeData().isHasSequence()
+ && match( node.getNodeData().getSequence().getName(),
+ query,
+ case_sensitive,
+ partial,
+ false ) ) {
+ match = true;
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.GeneName ) ) && node.getNodeData().isHasSequence()
+ && match( node.getNodeData().getSequence().getGeneName(),
+ query,
+ case_sensitive,
+ partial,
+ false ) ) {
+ match = true;
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceSymbol ) )
+ && node.getNodeData().isHasSequence() && match( node.getNodeData().getSequence().getSymbol(),
+ query,
+ case_sensitive,
+ partial,
+ false ) ) {
+ match = true;
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.SequenceAccession ) )
+ && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getAccession() != null )
+ && match( node.getNodeData().getSequence().getAccession().getValue(),
+ query,
+ case_sensitive,
+ partial,
+ false ) ) {
+ match = true;
+ }
+ if ( !match && ( ( ( ndf == null ) && search_domains ) || ( ndf == NDF.Domain ) )
+ && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) {
+ final DomainArchitecture da = node.getNodeData().getSequence().getDomainArchitecture();
+ I: for( int i = 0; i < da.getNumberOfDomains(); ++i ) {
+ if ( ( da.getDomain( i ).getConfidence() <= domains_confidence_threshold )
+ && match( da.getDomain( i ).getName(), query, case_sensitive, partial, false ) ) {
+ match = true;
+ break I;
+ }
+ }
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.Annotation ) ) && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getAnnotations() != null ) ) {
+ for( final Annotation ann : node.getNodeData().getSequence().getAnnotations() ) {
+ if ( match( ann.getDesc(), query, case_sensitive, partial, false ) ) {
+ match = true;
+ break;
+ }
+ if ( match( ann.getRef(), query, case_sensitive, partial, false ) ) {
+ match = true;
+ break;
+ }
+ }
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.CrossRef ) ) && node.getNodeData().isHasSequence()
+ && ( node.getNodeData().getSequence().getCrossReferences() != null ) ) {
+ for( final Accession x : node.getNodeData().getSequence().getCrossReferences() ) {
+ if ( match( x.getComment(), query, case_sensitive, partial, false ) ) {
+ match = true;
+ break;
+ }
+ if ( match( x.getSource(), query, case_sensitive, partial, false ) ) {
+ match = true;
+ break;
+ }
+ if ( match( x.getValue(), query, case_sensitive, partial, false ) ) {
+ match = true;
+ break;
+ }
+ }
+ }
+ if ( !match && ( ( ndf == null ) || ( ndf == NDF.BinaryCharacter ) )
+ && ( node.getNodeData().getBinaryCharacters() != null ) ) {
+ Iterator<String> it = node.getNodeData().getBinaryCharacters().getPresentCharacters().iterator();
+ I: while ( it.hasNext() ) {
+ if ( match( it.next(), query, case_sensitive, partial, false ) ) {
+ match = true;
+ break I;
+ }
+ }
+ it = node.getNodeData().getBinaryCharacters().getGainedCharacters().iterator();
+ I: while ( it.hasNext() ) {
+ if ( match( it.next(), query, case_sensitive, partial, false ) ) {
+ match = true;
+ break I;
+ }
+ }
+ }
+ if ( !match && ( ndf == NDF.MolecularSequence ) && node.getNodeData().isHasSequence()
+ && match( node.getNodeData().getSequence().getMolecularSequence(),
+ query,
+ case_sensitive,
+ true,
+ false ) ) {
+ match = true;
+ }
+ if ( !match ) {
+ all_matched = false;
+ break;
+ }
+ }
+ if ( all_matched ) {
+ nodes.add( node.getId() );
+ }
+ }
+ return nodes;
+ }
+
+ public static void setAllIndicatorsToZero( final Phylogeny phy ) {
+ for( final PhylogenyNodeIterator it = phy.iteratorPostorder(); it.hasNext(); ) {
+ it.next().setIndicator( ( byte ) 0 );
+ }
+ }
+
+ /**
+ * Convenience method.
+ * Sets value for the first confidence value (created if not present, values overwritten otherwise).
+ */
+ public static void setBootstrapConfidence( final PhylogenyNode node, final double bootstrap_confidence_value ) {
+ setConfidence( node, bootstrap_confidence_value, "bootstrap" );
+ }
+
+ public static void setBranchColorValue( final PhylogenyNode node, final Color color ) {
+ if ( node.getBranchData().getBranchColor() == null ) {
+ node.getBranchData().setBranchColor( new BranchColor() );
+ }
+ node.getBranchData().getBranchColor().setValue( color );