X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2Ftools%2FSequenceDataRetriver.java;h=fcb71fc003108bed3c56a40937b8c9b82ac037b9;hb=fbb463a0dc277aa6efa5231f6db554de3696b194;hp=508d60febe908149973a6dd3c4608d43bc18bdcd;hpb=0eaeb6c6f769b98d7604e1a1ba76225df227c762;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/tools/SequenceDataRetriver.java b/forester/java/src/org/forester/archaeopteryx/tools/SequenceDataRetriver.java index 508d60f..fcb71fc 100644 --- a/forester/java/src/org/forester/archaeopteryx/tools/SequenceDataRetriver.java +++ b/forester/java/src/org/forester/archaeopteryx/tools/SequenceDataRetriver.java @@ -21,29 +21,19 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.archaeopteryx.tools; import java.io.IOException; import java.net.UnknownHostException; import java.util.SortedSet; -import java.util.TreeSet; import javax.swing.JOptionPane; import org.forester.archaeopteryx.MainFrameApplication; import org.forester.archaeopteryx.TreePanel; import org.forester.phylogeny.Phylogeny; -import org.forester.phylogeny.PhylogenyNode; -import org.forester.phylogeny.data.Accession; -import org.forester.phylogeny.data.Identifier; -import org.forester.phylogeny.data.Sequence; -import org.forester.phylogeny.data.Taxonomy; -import org.forester.phylogeny.iterators.PhylogenyNodeIterator; -import org.forester.util.ForesterUtil; -import org.forester.util.SequenceIdParser; -import org.forester.ws.seqdb.SequenceDatabaseEntry; import org.forester.ws.seqdb.SequenceDbWsTools; public final class SequenceDataRetriver extends RunnableProcess { @@ -51,11 +41,7 @@ public final class SequenceDataRetriver extends RunnableProcess { private final Phylogeny _phy; private final MainFrameApplication _mf; private final TreePanel _treepanel; - private final static boolean DEBUG = true; - - private enum Db { - UNIPROT, EMBL, NCBI, NONE, REFSEQ; - } + public final static boolean DEBUG = false; public SequenceDataRetriver( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) { _phy = phy; @@ -63,17 +49,24 @@ public final class SequenceDataRetriver extends RunnableProcess { _treepanel = treepanel; } + @Override + public void run() { + execute(); + } + private void execute() { start( _mf, "sequence data" ); SortedSet not_found = null; try { - not_found = obtainSeqInformation( _phy ); + not_found = SequenceDbWsTools.obtainSeqInformation( _phy, + false, + true, + SequenceDbWsTools.DEFAULT_LINES_TO_RETURN ); } catch ( final UnknownHostException e ) { - final String what = "_"; //TODO FIXME JOptionPane.showMessageDialog( _mf, - "Could not connect to \"" + what + "\"", - "Network error during taxonomic information gathering", + e.getLocalizedMessage(), + "Network error during sequence data gathering", JOptionPane.ERROR_MESSAGE ); return; } @@ -81,7 +74,7 @@ public final class SequenceDataRetriver extends RunnableProcess { e.printStackTrace(); JOptionPane.showMessageDialog( _mf, e.toString(), - "Failed to obtain taxonomic information", + "Failed to obtain sequence data", JOptionPane.ERROR_MESSAGE ); return; } @@ -100,11 +93,10 @@ public final class SequenceDataRetriver extends RunnableProcess { } final StringBuffer sb = new StringBuffer(); if ( not_found.size() == 1 ) { - sb.append( "Data for the following sequence identifier was not found:\n" ); + sb.append( "For the following node no data was found:\n" ); } else { - sb.append( "Data for the following sequence identifiers was not found (total: " + not_found.size() - + "):\n" ); + sb.append( "For the following nodes no data was found (total: " + not_found.size() + "):\n" ); } int i = 0; for( final String string : not_found ) { @@ -140,114 +132,4 @@ public final class SequenceDataRetriver extends RunnableProcess { } } } - - public static SortedSet obtainSeqInformation( final Phylogeny phy ) throws IOException { - final SortedSet not_found = new TreeSet(); - for( final PhylogenyNodeIterator iter = phy.iteratorPostorder(); iter.hasNext(); ) { - final PhylogenyNode node = iter.next(); - final Sequence seq = node.getNodeData().isHasSequence() ? node.getNodeData().getSequence() : new Sequence() ; - final Taxonomy tax = node.getNodeData().isHasTaxonomy() ? node.getNodeData().getTaxonomy() : new Taxonomy() ; - - - 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 = SequenceDbWsTools.parseUniProtAccessor( node.getName() ) ) != 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; - } - - } - } - SequenceDatabaseEntry db_entry = null; - if ( !ForesterUtil.isEmpty( query ) ) { - if ( db == Db.UNIPROT ) { - if ( DEBUG ) { - System.out.println( "uniprot: " + query ); - } - db_entry = SequenceDbWsTools.obtainUniProtEntry( query, 200 ); - } - if ( ( db == Db.EMBL ) || ( ( db == Db.UNIPROT ) && ( db_entry == null ) ) ) { - if ( DEBUG ) { - System.out.println( "embl: " + query ); - } - db_entry = SequenceDbWsTools.obtainEmblEntry( new Identifier( query ), 200 ); - if ( ( db == Db.UNIPROT ) && ( db_entry != null ) ) { - db = Db.EMBL; - } - } - } - else if ( ( db == Db.REFSEQ ) && ( id != null ) ) { - db_entry = SequenceDbWsTools.obtainRefSeqEntryFromEmbl( id, 200 ); - } - else if ( ( db == Db.NCBI ) && ( id != null ) ) { - db_entry = SequenceDbWsTools.obtainEmblEntry( id, 200 ); - } - if ( ( db_entry != null ) && !db_entry.isEmpty() ) { - 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.getSequenceSymbol() ) ) { - seq.setSymbol( db_entry.getSequenceSymbol() ); - } - if ( !ForesterUtil.isEmpty( db_entry.getTaxonomyScientificName() ) ) { - tax.setScientificName( db_entry.getTaxonomyScientificName() ); - } - if ( !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() ); - } - } - return not_found; - } - - @Override - public void run() { - execute(); - } }