- if ( ext_nodes_only && node.isInternal() ) {
- continue;
- }
- String query = null;
- Identifier id = null;
- Db db = Db.NONE;
- if ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAccession() != null )
- && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() )
- && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() )
- && node.getNodeData().getSequence().getAccession().getValue().toLowerCase().startsWith( "uniprot" ) ) {
- query = node.getNodeData().getSequence().getAccession().getValue();
- db = Db.UNIPROT;
- }
- else if ( node.getNodeData().isHasSequence()
- && ( node.getNodeData().getSequence().getAccession() != null )
- && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() )
- && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() )
- && ( node.getNodeData().getSequence().getAccession().getValue().toLowerCase().startsWith( "embl" ) || node
- .getNodeData().getSequence().getAccession().getValue().toLowerCase().startsWith( "ebi" ) ) ) {
- query = node.getNodeData().getSequence().getAccession().getValue();
- db = Db.EMBL;
- }
- else if ( !ForesterUtil.isEmpty( node.getName() ) ) {
- if ( ( query = ForesterUtil.extractUniProtKbProteinSeqIdentifier( node ) ) != null ) {
- db = Db.UNIPROT;
- }
- else if ( ( id = SequenceIdParser.parse( node.getName() ) ) != null ) {
- if ( id.getProvider().equalsIgnoreCase( Identifier.NCBI ) ) {
- db = Db.NCBI;
- }
- else if ( id.getProvider().equalsIgnoreCase( Identifier.REFSEQ ) ) {
- db = Db.REFSEQ;
- }
- }
- }
- if ( db == Db.NONE ) {
- not_found.add( node.getName() );
- }
- SequenceDatabaseEntry db_entry = null;
- if ( !ForesterUtil.isEmpty( query ) ) {
- if ( db == Db.UNIPROT ) {
- if ( DEBUG ) {
- System.out.println( "uniprot: " + query );
- }
- db_entry = obtainUniProtEntry( query, lines_to_return );
- }
- if ( ( db == Db.EMBL ) || ( ( db == Db.UNIPROT ) && ( db_entry == null ) ) ) {
- if ( DEBUG ) {
- System.out.println( "embl: " + query );
- }
- db_entry = obtainEmblEntry( new Identifier( query ), lines_to_return );
- if ( ( db == Db.UNIPROT ) && ( db_entry != null ) ) {
- db = Db.EMBL;
- }
- }
- }
- else if ( ( db == Db.REFSEQ ) && ( id != null ) ) {
- db_entry = obtainRefSeqEntryFromEmbl( id, lines_to_return );
- }
- else if ( ( db == Db.NCBI ) && ( id != null ) ) {
- db_entry = obtainEmblEntry( id, lines_to_return ); //TODO ?
- }
- if ( ( db_entry != null ) && !db_entry.isEmpty() ) {
- final Sequence seq = node.getNodeData().isHasSequence() ? node.getNodeData().getSequence()
- : new Sequence();
- if ( !ForesterUtil.isEmpty( db_entry.getAccession() ) ) {
- String type = null;
- if ( db == Db.EMBL ) {
- type = "embl";
- }
- else if ( db == Db.UNIPROT ) {
- type = "uniprot";
- }
- else if ( db == Db.NCBI ) {
- type = "ncbi";
- }
- else if ( db == Db.REFSEQ ) {
- type = "refseq";
- }
- seq.setAccession( new Accession( db_entry.getAccession(), type ) );
- }
- if ( !ForesterUtil.isEmpty( db_entry.getSequenceName() ) ) {
- seq.setName( db_entry.getSequenceName() );
- }
- if ( !ForesterUtil.isEmpty( db_entry.getGeneName() ) ) {
- final String gn = db_entry.getGeneName().replace( ' ', '_' );
- try {
- seq.setSymbol( gn );
- }
- catch ( PhyloXmlDataFormatException e ) {
- // Eat this exception.
- }
- }
- if ( !ForesterUtil.isEmpty( db_entry.getGeneName() ) ) {
- // seq.addAnnotation( new Annotation( "GN", db_entry.getGeneName() ) );
- }
- if ( db_entry.getGoTerms() != null && !db_entry.getGoTerms().isEmpty() ) {
- for( final GoTerm go : db_entry.getGoTerms() ) {
- seq.addAnnotation( new Annotation( go.getGoId().getId(), go.getName() ) );
- }
- }
-
- final Taxonomy tax = node.getNodeData().isHasTaxonomy() ? node.getNodeData().getTaxonomy()
- : new Taxonomy();
- if ( !ForesterUtil.isEmpty( db_entry.getTaxonomyScientificName() ) ) {
- tax.setScientificName( db_entry.getTaxonomyScientificName() );
- }
- if ( allow_to_set_taxonomic_data && !ForesterUtil.isEmpty( db_entry.getTaxonomyIdentifier() ) ) {
- tax.setIdentifier( new Identifier( db_entry.getTaxonomyIdentifier(), "uniprot" ) );
- }
- node.getNodeData().setTaxonomy( tax );
- node.getNodeData().setSequence( seq );
- }
- else if ( db != Db.NONE ) {
- not_found.add( node.getName() );
- }
- try {
- Thread.sleep( 10 );// Sleep for 10 ms
- }
- catch ( final InterruptedException ie ) {