From 256204975bca8c5e5c00a9728caff30c52bd65cc Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Wed, 20 Nov 2013 02:59:16 +0000 Subject: [PATCH] inprogress --- .../org/forester/archaeopteryx/Configuration.java | 28 +++--- .../org/forester/archaeopteryx/ControlPanel.java | 15 ++- .../src/org/forester/archaeopteryx/TreePanel.java | 84 ++++++++++++++++ .../org/forester/archaeopteryx/TreePanelUtil.java | 103 ++++++++++++-------- .../java/src/org/forester/util/ForesterUtil.java | 1 + 5 files changed, 178 insertions(+), 53 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/Configuration.java b/forester/java/src/org/forester/archaeopteryx/Configuration.java index b09e7b9..689fde7 100644 --- a/forester/java/src/org/forester/archaeopteryx/Configuration.java +++ b/forester/java/src/org/forester/archaeopteryx/Configuration.java @@ -139,17 +139,18 @@ public final class Configuration { final static int swap = 4; final static int color_subtree = 5; final static int open_seq_web = 6; - final static int open_tax_web = 7; - final static int blast = 8; - final static int cut_subtree = 9; - final static int copy_subtree = 10; - final static int paste_subtree = 11; - final static int delete_subtree_or_node = 12; - final static int add_new_node = 13; - final static int edit_node_data = 14; - final static int sort_descendents = 15; - final static int get_ext_desc_data = 16; - final static int select_nodes = 17; + final static int open_pdb_web = 7; + final static int open_tax_web = 8; + final static int blast = 9; + final static int cut_subtree = 10; + final static int copy_subtree = 11; + final static int paste_subtree = 12; + final static int delete_subtree_or_node = 13; + final static int add_new_node = 14; + final static int edit_node_data = 15; + final static int sort_descendents = 16; + final static int get_ext_desc_data = 17; + final static int select_nodes = 18; // --------------------------- // Display options for trees // --------------------------- @@ -176,7 +177,7 @@ public final class Configuration { final static String clickto_options[][] = { { "Display Node Data", "display" }, { "Collapse/Uncollapse", "display" }, { "Root/Reroot", "display" }, { "Sub/Super Tree", "display" }, { "Swap Descendants", "display" }, - { "Colorize Subtree/Node(s)", "display" }, { "Open Sequence DB", "display" }, + { "Colorize Subtree/Node(s)", "display" }, { "Open Sequence DB", "display" }, { "Open PDB", "display" }, { "Open Taxonomy DB", "display" }, { "Blast", "display" }, { "Cut Subtree", "display" }, { "Copy Subtree", "display" }, { "Paste Subtree", "display" }, { "Delete Subtree/Node", "display" }, { "Add New Node", "display" }, { "Edit Node Data", "display" }, { "Sort Descendants", "display" }, @@ -834,6 +835,9 @@ public final class Configuration { else if ( name.equals( "open_seq_web" ) ) { index = Configuration.open_seq_web; } + else if ( name.equals( "open_pdb_web" ) ) { + index = Configuration.open_pdb_web; + } else if ( name.equals( "open_tax_web" ) ) { index = Configuration.open_tax_web; } diff --git a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java index 7586722..4c65e2a 100644 --- a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java +++ b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java @@ -137,6 +137,7 @@ final class ControlPanel extends JPanel implements ActionListener { private int _edit_node_data_item; private int _select_nodes_item; private int _get_ext_desc_data; + private int _open_pdb_item; private int _blast_item; // zooming and quick tree manipulation buttons: private JButton _zoom_in_x; @@ -1119,6 +1120,9 @@ final class ControlPanel extends JPanel implements ActionListener { else if ( action == _get_ext_desc_data ) { setActionWhenNodeClicked( NodeClickAction.GET_EXT_DESC_DATA ); } + else if ( action == _open_pdb_item ) { + setActionWhenNodeClicked( NodeClickAction.OPEN_PDB_WEB ); + } else { throw new RuntimeException( "unknown action: " + action ); } @@ -1733,6 +1737,14 @@ final class ControlPanel extends JPanel implements ActionListener { } cb_index++; } + if ( _configuration.doDisplayClickToOption( Configuration.open_pdb_web ) ) { + _open_pdb_item = cb_index; + addClickToOption( Configuration.open_pdb_web, _configuration.getClickToTitle( Configuration.open_pdb_web ) ); + if ( default_option == Configuration.open_pdb_web ) { + selected_index = cb_index; + } + cb_index++; + } if ( _configuration.doDisplayClickToOption( Configuration.open_tax_web ) ) { _open_tax_web_item = cb_index; addClickToOption( Configuration.open_tax_web, _configuration.getClickToTitle( Configuration.open_tax_web ) ); @@ -2053,6 +2065,7 @@ final class ControlPanel extends JPanel implements ActionListener { SELECT_NODES, SORT_DESCENDENTS, GET_EXT_DESC_DATA, - BLAST; + BLAST, + OPEN_PDB_WEB; } } diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index 9f7dd65..2833f8e 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -2850,6 +2850,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee case OPEN_TAX_WEB: openTaxWeb( node ); break; + case OPEN_PDB_WEB: + openPdbWeb( node ); + break; case CUT_SUBTREE: cutSubtree( node ); break; @@ -2942,6 +2945,22 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee return null; } + final private List getPdbAccs( final PhylogenyNode node ) { + final List pdb_ids = new ArrayList(); + if ( node.getNodeData().isHasSequence() ) { + final Sequence seq = node.getNodeData().getSequence(); + if ( !ForesterUtil.isEmpty( seq.getCrossReferences() ) ) { + final SortedSet cross_refs = seq.getCrossReferences(); + for( final Accession acc : cross_refs ) { + if ( acc.getSource().equalsIgnoreCase( "pdb" ) ) { + pdb_ids.add( acc ); + } + } + } + } + return pdb_ids; + } + final private boolean isCanOpenTaxWeb( final PhylogenyNode node ) { if ( node.getNodeData().isHasTaxonomy() && ( ( !ForesterUtil.isEmpty( node.getNodeData().getTaxonomy().getScientificName() ) ) @@ -3177,6 +3196,41 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _node_popup_menu_items[ i ].setEnabled( false ); } } + else if ( title.equals( Configuration.clickto_options[ Configuration.open_pdb_web ][ 0 ] ) ) { + final List accs = getPdbAccs( node ); + _node_popup_menu_items[ i ] = new JMenuItem( title ); + if ( !ForesterUtil.isEmpty( accs ) ) { + if ( accs.size() == 1 ) { + _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + + TreePanelUtil.pdbAccToString( accs, 0 ) + "]" ); + _node_popup_menu_items[ i ].setEnabled( true ); + } + else if ( accs.size() == 2 ) { + _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + + TreePanelUtil.pdbAccToString( accs, 0 ) + ", " + + TreePanelUtil.pdbAccToString( accs, 1 ) + "]" ); + _node_popup_menu_items[ i ].setEnabled( true ); + } + else if ( accs.size() == 3 ) { + _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + + TreePanelUtil.pdbAccToString( accs, 0 ) + ", " + + TreePanelUtil.pdbAccToString( accs, 1 ) + ", " + + TreePanelUtil.pdbAccToString( accs, 2 ) + "]" ); + _node_popup_menu_items[ i ].setEnabled( true ); + } + else { + _node_popup_menu_items[ i ].setText( _node_popup_menu_items[ i ].getText() + " [" + + TreePanelUtil.pdbAccToString( accs, 0 ) + ", " + + TreePanelUtil.pdbAccToString( accs, 1 ) + ", " + + TreePanelUtil.pdbAccToString( accs, 2 ) + ", + " + ( accs.size() - 3 ) + " more]" ); + _node_popup_menu_items[ i ].setEnabled( true ); + } + } + else { + _node_popup_menu_items[ i ].setEnabled( false ); + } + // + } else if ( title.equals( Configuration.clickto_options[ Configuration.open_tax_web ][ 0 ] ) ) { _node_popup_menu_items[ i ].setEnabled( isCanOpenTaxWeb( node ) ); } @@ -3297,6 +3351,36 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } + final private void openPdbWeb( final PhylogenyNode node ) { + final List pdb_ids = getPdbAccs( node ); + if ( ForesterUtil.isEmpty( pdb_ids ) ) { + cannotOpenBrowserWarningMessage( "PDB" ); + return; + } + final List uri_strs = TreePanelUtil.createUrisForPdbWeb( node, pdb_ids, getConfiguration(), this ); + if ( !ForesterUtil.isEmpty( uri_strs ) ) { + for( final String uri_str : uri_strs ) { + try { + AptxUtil.launchWebBrowser( new URI( uri_str ), + isApplet(), + isApplet() ? obtainApplet() : null, + "_aptx_seq" ); + } + catch ( final IOException e ) { + AptxUtil.showErrorMessage( this, e.toString() ); + e.printStackTrace(); + } + catch ( final URISyntaxException e ) { + AptxUtil.showErrorMessage( this, e.toString() ); + e.printStackTrace(); + } + } + } + else { + cannotOpenBrowserWarningMessage( "PDB" ); + } + } + final private void openTaxWeb( final PhylogenyNode node ) { if ( !isCanOpenTaxWeb( node ) ) { cannotOpenBrowserWarningMessage( "taxonomic" ); diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java b/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java index 61db054..5b5537c 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanelUtil.java @@ -22,6 +22,7 @@ import org.forester.analysis.TaxonomyDataManager; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyMethods; import org.forester.phylogeny.PhylogenyNode; +import org.forester.phylogeny.data.Accession; import org.forester.phylogeny.data.Annotation; import org.forester.phylogeny.data.BranchColor; import org.forester.phylogeny.data.NodeData.NODE_DATA; @@ -36,46 +37,6 @@ import org.forester.ws.seqdb.UniProtTaxonomy; public class TreePanelUtil { - static int makeSB( final List data, final Options optz, final StringBuilder sb ) { - final SortedMap map = new TreeMap(); - if ( ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ ) - && ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ_FASTA ) ) { - for( final String d : data ) { - if ( !ForesterUtil.isEmpty( d ) ) { - if ( map.containsKey( d ) ) { - map.put( d, map.get( d ) + 1 ); - } - else { - map.put( d, 1 ); - } - } - } - } - int size = 0; - if ( ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ ) - && ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ_FASTA ) ) { - for( final Entry e : map.entrySet() ) { - final String v = e.getKey(); - final Object c = e.getValue(); - sb.append( v ); - sb.append( "\t" ); - sb.append( c ); - sb.append( ForesterUtil.LINE_SEPARATOR ); - } - size = map.size(); - } - else { - for( final String d : data ) { - if ( !ForesterUtil.isEmpty( d ) ) { - sb.append( d ); - sb.append( ForesterUtil.LINE_SEPARATOR ); - } - } - size = data.size(); - } - return size; - } - public final static String createUriForSeqWeb( final PhylogenyNode node, final Configuration conf, final TreePanel tp ) { @@ -139,6 +100,21 @@ public class TreePanelUtil { return uri_str; } + public static List createUrisForPdbWeb( final PhylogenyNode node, + final List pdb_accs, + final Configuration configuration, + final TreePanel treePanel ) { + final List uris = new ArrayList(); + if ( !ForesterUtil.isEmpty( pdb_accs ) ) { + for( final Accession pdb_acc : pdb_accs ) { + if ( !ForesterUtil.isEmpty( pdb_acc.getValue() ) ) { + uris.add( ForesterUtil.PDB + pdb_acc.getValue() ); + } + } + } + return uris; + } + /** * Returns the set of distinct taxonomies of * all external nodes of node. @@ -499,6 +475,46 @@ public class TreePanelUtil { .getSynonyms().isEmpty() ); } + static int makeSB( final List data, final Options optz, final StringBuilder sb ) { + final SortedMap map = new TreeMap(); + if ( ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ ) + && ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ_FASTA ) ) { + for( final String d : data ) { + if ( !ForesterUtil.isEmpty( d ) ) { + if ( map.containsKey( d ) ) { + map.put( d, map.get( d ) + 1 ); + } + else { + map.put( d, 1 ); + } + } + } + } + int size = 0; + if ( ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ ) + && ( optz.getExtDescNodeDataToReturn() != NODE_DATA.SEQUENCE_MOL_SEQ_FASTA ) ) { + for( final Entry e : map.entrySet() ) { + final String v = e.getKey(); + final Object c = e.getValue(); + sb.append( v ); + sb.append( "\t" ); + sb.append( c ); + sb.append( ForesterUtil.LINE_SEPARATOR ); + } + size = map.size(); + } + else { + for( final String d : data ) { + if ( !ForesterUtil.isEmpty( d ) ) { + sb.append( d ); + sb.append( ForesterUtil.LINE_SEPARATOR ); + } + } + size = data.size(); + } + return size; + } + final static char normalizeCharForRGB( char c ) { c -= 65; c *= 10.2; @@ -507,6 +523,13 @@ public class TreePanelUtil { return c; } + final static String pdbAccToString( final List accs, final int i ) { + if ( ForesterUtil.isEmpty( accs.get( i ).getComment() ) ) { + return accs.get( i ).getValue(); + } + return accs.get( i ).getValue() + " (" + accs.get( i ).getComment().toLowerCase() + ")"; + } + final static Phylogeny subTree( final PhylogenyNode new_root, final Phylogeny source_phy ) { final Phylogeny new_phy = new Phylogeny(); new_phy.setRooted( true ); diff --git a/forester/java/src/org/forester/util/ForesterUtil.java b/forester/java/src/org/forester/util/ForesterUtil.java index 1908f8f..7492f1e 100644 --- a/forester/java/src/org/forester/util/ForesterUtil.java +++ b/forester/java/src/org/forester/util/ForesterUtil.java @@ -91,6 +91,7 @@ public final class ForesterUtil { public static final String NCBI_NUCCORE = "http://www.ncbi.nlm.nih.gov/nuccore/"; public final static String UNIPROT_KB = "http://www.uniprot.org/uniprot/"; public static final String NCBI_GI = "http://www.ncbi.nlm.nih.gov/protein/gi:"; + public static final String PDB = "http://www.pdb.org/pdb/explore/explore.do?pdbId="; static { final DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator( '.' ); -- 1.7.10.2