import java.net.UnknownHostException;
import java.util.SortedSet;
import java.util.TreeSet;
-import java.util.regex.Pattern;
import javax.swing.JOptionPane;
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;
-public final class SequenceDataRetriver implements Runnable {
+public final class SequenceDataRetriver extends RunnableProcess {
- // uniprot/expasy accession number format (6 chars):
- // letter digit letter-or-digit letter-or-digit letter-or-digit digit
- private final static Pattern UNIPROT_AC_PATTERN = Pattern.compile( "[A-NR-ZOPQ]\\d[A-Z0-9]{3}\\d" );
private final Phylogeny _phy;
private final MainFrameApplication _mf;
private final TreePanel _treepanel;
- private final static boolean DEBUG = true;
+ private final static boolean DEBUG = false;
private enum Db {
- UNKNOWN, UNIPROT;
+ UNKNOWN, UNIPROT, EMBL;
}
public SequenceDataRetriver( final MainFrameApplication mf, final TreePanel treepanel, final Phylogeny phy ) {
}
private void execute() {
- _mf.getMainPanel().getCurrentTreePanel().setWaitCursor();
+ start( _mf, "sequence data" );
SortedSet<String> not_found = null;
try {
not_found = obtainSeqInformation( _phy );
}
catch ( final UnknownHostException e ) {
- _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
JOptionPane.showMessageDialog( _mf,
"Could not connect to \"" + getBaseUrl() + "\"",
"Network error during taxonomic information gathering",
return;
}
catch ( final IOException e ) {
- _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
e.printStackTrace();
JOptionPane.showMessageDialog( _mf,
e.toString(),
return;
}
finally {
- _mf.getMainPanel().getCurrentTreePanel().setArrowCursor();
+ end( _mf );
}
_treepanel.setTree( _phy );
_mf.showWhole();
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( "Data for the following sequence identifier was not found:\n" );
}
else {
- sb.append( "The following identifiers were not found (total: " + not_found.size() + "):\n" );
+ sb.append( "Data for the following sequence identifiers was not found (total: " + not_found.size()
+ + "):\n" );
}
int i = 0;
for( final String string : not_found ) {
try {
JOptionPane.showMessageDialog( _mf,
sb.toString(),
- "UniProt Sequence Tool Completed",
+ "Sequence Tool Completed",
JOptionPane.WARNING_MESSAGE );
}
catch ( final Exception e ) {
}
}
- synchronized public static SortedSet<String> obtainSeqInformation( final Phylogeny phy ) throws IOException {
+ public static SortedSet<String> obtainSeqInformation( final Phylogeny phy ) throws IOException {
final SortedSet<String> not_found = new TreeSet<String>();
for( final PhylogenyNodeIterator iter = phy.iteratorPostorder(); iter.hasNext(); ) {
final PhylogenyNode node = iter.next();
query = node.getNodeData().getSequence().getAccession().getValue();
db = Db.UNIPROT;
}
- else if ( !ForesterUtil.isEmpty( node.getName() ) ) {
- query = node.getName();
+ 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;
}
- if ( !ForesterUtil.isEmpty( query ) ) {
- if ( query.indexOf( '/' ) > 0 ) {
- query = query.substring( 0, query.indexOf( '/' ) );
- }
- if ( query.indexOf( '.' ) > 0 ) {
- query = query.substring( 0, query.indexOf( '.' ) );
+ else if ( !ForesterUtil.isEmpty( node.getName() ) ) {
+ if ( ( query = UniProtWsTools.parseUniProtAccessor( node.getName() ) ) != null ) {
+ db = Db.UNIPROT;
}
- if ( query.indexOf( '_' ) > 0 ) {
- query = query.substring( 0, query.indexOf( '_' ) );
+ else if ( ( query = DatabaseTools.parseGenbankAccessor( node.getName() ) ) != null ) {
+ db = Db.EMBL;
}
+ }
+ if ( !ForesterUtil.isEmpty( query ) ) {
SequenceDatabaseEntry db_entry = null;
- if ( ( db == Db.UNIPROT ) || UNIPROT_AC_PATTERN.matcher( query ).matches() ) {
+ if ( db == Db.UNIPROT ) {
if ( DEBUG ) {
System.out.println( "uniprot: " + query );
}
// Ignore.
}
}
- if ( db_entry != null ) {
+ if ( ( db == Db.EMBL ) || ( ( db == Db.UNIPROT ) && ( db_entry == null ) ) ) {
+ if ( DEBUG ) {
+ System.out.println( "embl: " + query );
+ }
+ try {
+ db_entry = UniProtWsTools.obtainEmblEntry( query, 200 );
+ }
+ catch ( final FileNotFoundException e ) {
+ // Ignore.
+ }
+ if ( ( db == Db.UNIPROT ) && ( db_entry != null ) ) {
+ db = Db.EMBL;
+ }
+ }
+ if ( ( db_entry != null ) && !db_entry.isEmpty() ) {
if ( !ForesterUtil.isEmpty( db_entry.getAccession() ) ) {
- seq.setAccession( new Accession( db_entry.getAccession(), "uniprot" ) );
+ String type = null;
+ if ( db == Db.EMBL ) {
+ type = "embl";
+ }
+ else if ( db == Db.UNIPROT ) {
+ type = "uniprot";
+ }
+ seq.setAccession( new Accession( db_entry.getAccession(), type ) );
}
if ( !ForesterUtil.isEmpty( db_entry.getSequenceName() ) ) {
seq.setName( db_entry.getSequenceName() );