removed applet code
[jalview.git] / forester / java / src / org / forester / archaeopteryx / tools / Blast.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.archaeopteryx.tools;
27
28 import java.io.IOException;
29 import java.net.URI;
30 import java.net.URISyntaxException;
31
32 import org.forester.archaeopteryx.AptxUtil;
33 import org.forester.archaeopteryx.TreePanel;
34 import org.forester.phylogeny.PhylogenyNode;
35 import org.forester.phylogeny.data.Accession;
36 import org.forester.util.ForesterUtil;
37 import org.forester.util.SequenceAccessionTools;
38
39 public final class Blast {
40
41     final public static void openNcbiBlastWeb( final String query,
42                                                final boolean is_nucleic_acids,
43                                              
44                                                final TreePanel p ) {
45         //http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=Web&PAGE=Proteins&DATABASE=swissprot&QUERY=gi|163848401
46         final StringBuilder uri_str = new StringBuilder();
47         uri_str.append( "http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=Web&DATABASE=nr&PAGE=" );
48         if ( is_nucleic_acids ) {
49             uri_str.append( "Nucleotide" );
50         }
51         else {
52             uri_str.append( "Proteins" );
53         }
54         uri_str.append( "&QUERY=" );
55         uri_str.append( query );
56         try {
57             AptxUtil.launchWebBrowser( new URI( uri_str.toString() ), "_aptx_blast" );
58         }
59         catch ( final IOException e ) {
60             AptxUtil.showErrorMessage( p, e.toString() );
61             e.printStackTrace();
62         }
63         catch ( final URISyntaxException e ) {
64             AptxUtil.showErrorMessage( p, e.toString() );
65             e.printStackTrace();
66         }
67     }
68
69     final public static String obtainQueryForBlast( final PhylogenyNode node ) {
70         String query = "";
71         if ( node.getNodeData().isHasSequence() ) {
72             if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) {
73                 query = node.getNodeData().getSequence().getMolecularSequence();
74             }
75             if ( ForesterUtil.isEmpty( query ) && ( node.getNodeData().getSequence().getAccession() != null )
76                     && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() ) ) {
77                 final Accession id = SequenceAccessionTools.parseAccessorFromString( node.getNodeData().getSequence()
78                                                                                      .getAccession().getValue() );
79                 if ( id != null ) {
80                     query = id.getValue();
81                 }
82             }
83             if ( ForesterUtil.isEmpty( query ) && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getName() ) ) {
84                 final Accession id = SequenceAccessionTools.parseAccessorFromString( node.getNodeData().getSequence()
85                                                                                      .getName() );
86                 if ( id != null ) {
87                     query = id.getValue();
88                 }
89             }
90             if ( ForesterUtil.isEmpty( query ) && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getSymbol() ) ) {
91                 final Accession id = SequenceAccessionTools.parseAccessorFromString( node.getNodeData().getSequence()
92                                                                                      .getSymbol() );
93                 if ( id != null ) {
94                     query = id.getValue();
95                 }
96             }
97             if ( ForesterUtil.isEmpty( query )
98                     && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getGeneName() ) ) {
99                 final Accession id = SequenceAccessionTools.parseAccessorFromString( node.getNodeData().getSequence()
100                                                                                      .getGeneName() );
101                 if ( id != null ) {
102                     query = id.getValue();
103                 }
104             }
105         }
106         if ( ForesterUtil.isEmpty( query ) && !ForesterUtil.isEmpty( node.getName() ) ) {
107             final Accession id = SequenceAccessionTools.parseAccessorFromString( node.getName() );
108             if ( id != null ) {
109                 query = id.getValue();
110             }
111         }
112         return query;
113     }
114
115     final public static boolean isContainsQueryForBlast( final PhylogenyNode node ) {
116         return !ForesterUtil.isEmpty( obtainQueryForBlast( node ) );
117     }
118 }