X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2Ftools%2FSequenceDataRetriver.java;h=1cd6b54b45431d8e929827db6692596252cdc227;hb=3087ea10ac51cf1a8b2eb8d8abe010513ce9998f;hp=5b454e36d7b79e18571e2752da14d06e7b7a19fc;hpb=e4f95087154c70d569fe54d8f08af7d4f218df0c;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 5b454e3..1cd6b54 100644 --- a/forester/java/src/org/forester/archaeopteryx/tools/SequenceDataRetriver.java +++ b/forester/java/src/org/forester/archaeopteryx/tools/SequenceDataRetriver.java @@ -21,42 +21,27 @@ // 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.FileNotFoundException; 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.ws.uniprot.DatabaseTools; -import org.forester.ws.uniprot.SequenceDatabaseEntry; -import org.forester.ws.uniprot.UniProtWsTools; +import org.forester.ws.seqdb.SequenceDbWsTools; -public final class SequenceDataRetriver implements Runnable { +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 { - UNKNOWN, UNIPROT, EMBL; - } + public final static boolean DEBUG = false; public SequenceDataRetriver( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) { _phy = phy; @@ -64,35 +49,37 @@ public final class SequenceDataRetriver implements Runnable { _treepanel = treepanel; } - private String getBaseUrl() { - return UniProtWsTools.BASE_URL; + @Override + public void run() { + execute(); } private void execute() { - _mf.getMainPanel().getCurrentTreePanel().setWaitCursor(); + 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 ) { - _mf.getMainPanel().getCurrentTreePanel().setArrowCursor(); JOptionPane.showMessageDialog( _mf, - "Could not connect to \"" + getBaseUrl() + "\"", - "Network error during taxonomic information gathering", + e.getLocalizedMessage(), + "Network error during sequence data gathering", JOptionPane.ERROR_MESSAGE ); return; } catch ( final IOException e ) { - _mf.getMainPanel().getCurrentTreePanel().setArrowCursor(); e.printStackTrace(); JOptionPane.showMessageDialog( _mf, e.toString(), - "Failed to obtain taxonomic information", + "Failed to obtain sequence data", JOptionPane.ERROR_MESSAGE ); return; } finally { - _mf.getMainPanel().getCurrentTreePanel().setArrowCursor(); + end( _mf ); } _treepanel.setTree( _phy ); _mf.showWhole(); @@ -105,12 +92,11 @@ public final class SequenceDataRetriver implements Runnable { max = 20; } final StringBuffer sb = new StringBuffer(); - sb.append( "Not all identifiers could be resolved.\n" ); if ( not_found.size() == 1 ) { - sb.append( "The following identifier was not found:\n" ); + sb.append( "For the following node no data was found:\n" ); } else { - sb.append( "The following identifiers were 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 ) { @@ -127,18 +113,18 @@ public final class SequenceDataRetriver implements Runnable { try { JOptionPane.showMessageDialog( _mf, sb.toString(), - "UniProt Sequence Tool Completed", + "Sequence Tool Completed", JOptionPane.WARNING_MESSAGE ); } catch ( final Exception e ) { - // Not important if this fails, do nothing. + // Not important if this fails, do nothing. } } else { try { JOptionPane.showMessageDialog( _mf, - "UniProt sequence tool successfully completed", - "UniProt Sequence Tool Completed", + "Sequence tool successfully completed", + "Sequence Tool Completed", JOptionPane.INFORMATION_MESSAGE ); } catch ( final Exception e ) { @@ -146,104 +132,4 @@ public final class SequenceDataRetriver implements Runnable { } } } - - 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(); - Sequence seq = null; - Taxonomy tax = null; - if ( node.getNodeData().isHasSequence() ) { - seq = node.getNodeData().getSequence(); - } - else { - seq = new Sequence(); - } - if ( node.getNodeData().isHasTaxonomy() ) { - tax = node.getNodeData().getTaxonomy(); - } - else { - tax = new Taxonomy(); - } - String query = null; - Db db = Db.UNKNOWN; - 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 = UniProtWsTools.parseUniProtAccessor( node.getName() ) ) != null ) { - db = Db.UNIPROT; - } - else if ( ( query = DatabaseTools.parseGenbankAccessor( node.getName() ) ) != null ) { - db = Db.EMBL; - } - } - if ( !ForesterUtil.isEmpty( query ) ) { - SequenceDatabaseEntry db_entry = null; - if ( db == Db.UNIPROT ) { - if ( DEBUG ) { - System.out.println( "uniprot: " + query ); - } - try { - db_entry = UniProtWsTools.obtainUniProtEntry( query, 200 ); - } - catch ( final FileNotFoundException e ) { - // Ignore. - } - } - else if ( db == Db.EMBL ) { - if ( DEBUG ) { - System.out.println( "embl: " + query ); - } - try { - db_entry = UniProtWsTools.obtainEmblEntry( query, 200 ); - } - catch ( final FileNotFoundException e ) { - // Ignore. - } - } - if ( db_entry != null ) { - if ( !ForesterUtil.isEmpty( db_entry.getAccession() ) ) { - seq.setAccession( new Accession( db_entry.getAccession(), "uniprot" ) ); - } - 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 { - not_found.add( node.getName() ); - } - } - } - return not_found; - } - - @Override - public void run() { - execute(); - } }