X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FTreePanel.java;h=9e6fcc6a0036a54b9c098a19293b94e836e4611d;hb=a9cc2cc5c9cda0ab49f26ccfb7a1aa30531e6ecf;hp=5ae8e02cf43a19a7cc47939f86ee6fb142a89c87;hpb=59b6fbdbe75f9f7b76bb97c9e1a281880c53a330;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index 5ae8e02..9e6fcc6 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -77,6 +77,7 @@ import java.util.Hashtable; import java.util.List; import java.util.Set; import java.util.SortedSet; +import java.util.regex.Matcher; import javax.swing.BorderFactory; import javax.swing.JApplet; @@ -100,6 +101,7 @@ import org.forester.archaeopteryx.phylogeny.data.RenderableVector; import org.forester.archaeopteryx.tools.Blast; import org.forester.archaeopteryx.tools.ImageLoader; import org.forester.io.parsers.phyloxml.PhyloXmlUtil; +import org.forester.io.writers.SequenceWriter; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY; @@ -2909,18 +2911,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return Blast.isContainsQueryForBlast( node ); } - final private boolean isCanOpenSeqWeb( final PhylogenyNode node ) { - if ( node.getNodeData().isHasSequence() - && ( node.getNodeData().getSequence().getAccession() != null ) - && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) - && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() ) - && getConfiguration().isHasWebLink( node.getNodeData().getSequence().getAccession().getSource() - .toLowerCase() ) ) { - return true; - } - return false; - } - final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) { if ( node.getNodeData().isHasTaxonomy() && ( ( ( node.getNodeData().getTaxonomy().getIdentifier() != null ) @@ -3227,6 +3217,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return "Sequence Symbols"; case SEQUENCE_MOL_SEQ: return "Molecular Sequences"; + case SEQUENCE_MOL_SEQ_FASTA: + return "Molecular Sequences (Fasta)"; case SEQUENCE_ACC: return "Sequence Accessors"; case TAXONOMY_SCIENTIFIC_NAME: @@ -3241,36 +3233,114 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } + final private boolean isCanOpenSeqWeb( final PhylogenyNode node ) { + if ( node.getNodeData().isHasSequence() + && ( node.getNodeData().getSequence().getAccession() != null ) + && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) + && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() ) + && getConfiguration().isHasWebLink( node.getNodeData().getSequence().getAccession().getSource() + .toLowerCase() ) ) { + return true; + } + if ( !ForesterUtil.isEmpty( node.getName() ) + && ( AptxUtil.UNIPROT_KB_PATTERN_1.matcher( node.getName() ).find() + || AptxUtil.UNIPROT_KB_PATTERN_2.matcher( node.getName() ).find() + ) ) { + return true; + } + if ( node.getNodeData().isHasSequence() ) { + Sequence seq = node.getNodeData().getSequence(); + if ( !ForesterUtil.isEmpty( seq.getName() ) && ( AptxUtil.UNIPROT_KB_PATTERN_1.matcher( seq.getName() ).find() + || AptxUtil.UNIPROT_KB_PATTERN_2.matcher( seq.getName() ).find() + + ) ) { + return true; + } + if ( !ForesterUtil.isEmpty( seq.getSymbol() ) + && ( AptxUtil.UNIPROT_KB_PATTERN_1.matcher( seq.getSymbol() ).find() + || AptxUtil.UNIPROT_KB_PATTERN_2.matcher( seq.getSymbol() ).find() ) ) { + return true; + } + if ( ( node.getNodeData().getSequence().getAccession() != null ) + && !ForesterUtil.isEmpty( seq.getAccession().getValue() ) + && ( AptxUtil.UNIPROT_KB_PATTERN_1.matcher( seq.getAccession().getValue() ).find() + + || AptxUtil.UNIPROT_KB_PATTERN_2.matcher( seq.getAccession().getValue() ).find() + ) ) { + return true; + } + } + return false; + } + final private void openSeqWeb( final PhylogenyNode node ) { if ( !isCanOpenSeqWeb( node ) ) { cannotOpenBrowserWarningMessage( "sequence" ); return; } String uri_str = null; - final Sequence seq = node.getNodeData().getSequence(); - final String source = seq.getAccession().getSource().toLowerCase(); - String url; - if ( source.toLowerCase().equals( "ncbi" ) ) { - url = Constants.NCBI_ALL_DATABASE_SEARCH; + if ( node.getNodeData().isHasSequence() + && ( node.getNodeData().getSequence().getAccession() != null ) + && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) + && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() ) + && getConfiguration().isHasWebLink( node.getNodeData().getSequence().getAccession().getSource() + .toLowerCase() ) ) { + final Sequence seq = node.getNodeData().getSequence(); + final String source = seq.getAccession().getSource().toLowerCase(); + String url; + if ( source.toLowerCase().equals( "ncbi" ) ) { + url = Constants.NCBI_ALL_DATABASE_SEARCH; + } + else { + final WebLink weblink = getConfiguration().getWebLink( source ); + url = weblink.getUrl().toString(); + } + try { + uri_str = url + URLEncoder.encode( seq.getAccession().getValue(), ForesterConstants.UTF8 ); + } + catch ( final UnsupportedEncodingException e ) { + AptxUtil.showErrorMessage( this, e.toString() ); + e.printStackTrace(); + } } else { - final WebLink weblink = getConfiguration().getWebLink( source ); - url = weblink.getUrl().toString(); - } - try { - uri_str = url + URLEncoder.encode( seq.getAccession().getValue(), ForesterConstants.UTF8 ); - } - catch ( final UnsupportedEncodingException e ) { - AptxUtil.showErrorMessage( this, e.toString() ); - e.printStackTrace(); + String upkb = null; + if ( node.getNodeData().isHasSequence() ) { + Sequence seq = node.getNodeData().getSequence(); + if ( !ForesterUtil.isEmpty( seq.getSymbol() ) + && AptxUtil.UNIPROT_KB_PATTERN_2.matcher( seq.getSymbol() ).find() ) { + upkb = AptxUtil.UNIPROT_KB_PATTERN_2.matcher( seq.getSymbol() ).group(); + } + else if ( !ForesterUtil.isEmpty( seq.getName() ) + && AptxUtil.UNIPROT_KB_PATTERN_2.matcher( seq.getName() ).find() ) { + upkb = AptxUtil.UNIPROT_KB_PATTERN_2.matcher( seq.getName() ).group(); + } + else if ( ( node.getNodeData().getSequence().getAccession() != null ) + && !ForesterUtil.isEmpty( seq.getAccession().getValue() ) + && AptxUtil.UNIPROT_KB_PATTERN_2.matcher( seq.getAccession().getValue() ).find() ) { + upkb = AptxUtil.UNIPROT_KB_PATTERN_2.matcher( seq.getAccession().getValue() ).group(); + } + } + if ( ForesterUtil.isEmpty( upkb ) && !ForesterUtil.isEmpty( node.getName() ) ) { + final Matcher m = AptxUtil.UNIPROT_KB_PATTERN_2.matcher( node.getName() ); + if ( m.find() ) { + upkb = m.group(); + } + } + try { + uri_str = AptxUtil.UNIPROT_KB + URLEncoder.encode( upkb, ForesterConstants.UTF8 ); + } + catch ( final UnsupportedEncodingException e ) { + AptxUtil.showErrorMessage( this, e.toString() ); + e.printStackTrace(); + } } if ( !ForesterUtil.isEmpty( uri_str ) ) { try { - JApplet applet = null; - if ( isApplet() ) { - applet = obtainApplet(); - } - AptxUtil.launchWebBrowser( new URI( uri_str ), isApplet(), applet, "_aptx_seq" ); + AptxUtil.launchWebBrowser( new URI( uri_str ), + isApplet(), + isApplet() ? obtainApplet() : null, + "_aptx_seq" ); } catch ( final IOException e ) { AptxUtil.showErrorMessage( this, e.toString() ); @@ -4530,10 +4600,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } final private void paintOvRectangle( final Graphics2D g ) { - final float w_ratio = ( float ) getWidth() / getVisibleRect().width; - final float h_ratio = ( float ) getHeight() / getVisibleRect().height; - final float x_ratio = ( float ) getWidth() / getVisibleRect().x; - final float y_ratio = ( float ) getHeight() / getVisibleRect().y; + final float w_ratio = ( ( float ) getWidth() ) / getVisibleRect().width; + final float h_ratio = ( ( float ) getHeight() ) / getVisibleRect().height; + final float x_ratio = ( ( float ) getWidth() ) / getVisibleRect().x; + final float y_ratio = ( ( float ) getHeight() ) / getVisibleRect().y; final float width = getOvMaxWidth() / w_ratio; final float height = getOvMaxHeight() / h_ratio; final float x = getVisibleRect().x + getOvXPosition() + ( getOvMaxWidth() / x_ratio ); @@ -5060,6 +5130,21 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee data.add( n.getNodeData().getSequence().getMolecularSequence() ); } break; + case SEQUENCE_MOL_SEQ_FASTA: + final StringBuilder sb = new StringBuilder(); + if ( n.getNodeData().isHasSequence() + && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getMolecularSequence() ) ) { + if ( !ForesterUtil.isEmpty( n.getNodeData().getSequence().getName() ) ) { + sb.append( SequenceWriter.toFasta( n.getNodeData().getSequence().getName(), n.getNodeData() + .getSequence().getMolecularSequence(), 60 ) ); + } + else { + sb.append( SequenceWriter.toFasta( n.getName(), n.getNodeData().getSequence() + .getMolecularSequence(), 60 ) ); + } + data.add( sb.toString() ); + } + break; case SEQUENCE_ACC: if ( n.getNodeData().isHasSequence() && ( n.getNodeData().getSequence().getAccession() != null ) && !ForesterUtil.isEmpty( n.getNodeData().getSequence().getAccession().toString() ) ) {