work on: add ability to perform GSDI in applets
[jalview.git] / forester / java / src / org / forester / archaeopteryx / AptxUtil.java
index 823e18f..89a0cda 100644 (file)
@@ -75,10 +75,10 @@ import org.forester.io.parsers.tol.TolParser;
 import org.forester.io.parsers.util.ParserUtils;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
+import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY;
 import org.forester.phylogeny.PhylogenyNode;
 import org.forester.phylogeny.data.Accession;
 import org.forester.phylogeny.data.BranchColor;
-import org.forester.phylogeny.data.Sequence;
 import org.forester.phylogeny.data.Taxonomy;
 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
 import org.forester.phylogeny.factories.PhylogenyFactory;
@@ -107,22 +107,10 @@ public final class AptxUtil {
                                                    final Configuration conf,
                                                    final TreePanel tp ) {
         String uri_str = null;
-        if ( node.getNodeData().isHasSequence() && ( node.getNodeData().getSequence().getAccession() != null )
-                && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() )
-                && !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getValue() )
-                && conf.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 = conf.getWebLink( source );
-                url = weblink.getUrl().toString();
-            }
+        final String upkb = ForesterUtil.extractUniProtKbProteinSeqIdentifier( node );
+        if ( !ForesterUtil.isEmpty( upkb ) ) {
             try {
-                uri_str = url + URLEncoder.encode( seq.getAccession().getValue(), ForesterConstants.UTF8 );
+                uri_str = ForesterUtil.UNIPROT_KB + URLEncoder.encode( upkb, ForesterConstants.UTF8 );
             }
             catch ( final UnsupportedEncodingException e ) {
                 showErrorMessage( tp, e.toString() );
@@ -130,10 +118,15 @@ public final class AptxUtil {
             }
         }
         if ( ForesterUtil.isEmpty( uri_str ) ) {
-            final String upkb = ForesterUtil.extractUniProtKbProteinSeqIdentifier( node );
-            if ( !ForesterUtil.isEmpty( upkb ) ) {
+            final String v = ForesterUtil.extractGenbankAccessor( node );
+            if ( !ForesterUtil.isEmpty( v ) ) {
                 try {
-                    uri_str = ForesterUtil.UNIPROT_KB + URLEncoder.encode( upkb, ForesterConstants.UTF8 );
+                    if ( SequenceIdParser.isProtein( v ) ) {
+                        uri_str = ForesterUtil.NCBI_PROTEIN + URLEncoder.encode( v, ForesterConstants.UTF8 );
+                    }
+                    else {
+                        uri_str = ForesterUtil.NCBI_NUCCORE + URLEncoder.encode( v, ForesterConstants.UTF8 );
+                    }
                 }
                 catch ( final UnsupportedEncodingException e ) {
                     showErrorMessage( tp, e.toString() );
@@ -142,7 +135,7 @@ public final class AptxUtil {
             }
         }
         if ( ForesterUtil.isEmpty( uri_str ) ) {
-            final String v = ForesterUtil.extractGenbankAccessor( node );
+            final String v = ForesterUtil.extractRefSeqAccessorAccessor( node );
             if ( !ForesterUtil.isEmpty( v ) ) {
                 try {
                     if ( SequenceIdParser.isProtein( v ) ) {
@@ -159,15 +152,10 @@ public final class AptxUtil {
             }
         }
         if ( ForesterUtil.isEmpty( uri_str ) ) {
-            final String v = ForesterUtil.extractRefSeqAccessorAccessor( node );
+            final String v = ForesterUtil.extractGInumber( node );
             if ( !ForesterUtil.isEmpty( v ) ) {
                 try {
-                    if ( SequenceIdParser.isProtein( v ) ) {
-                        uri_str = ForesterUtil.NCBI_PROTEIN + URLEncoder.encode( v, ForesterConstants.UTF8 );
-                    }
-                    else {
-                        uri_str = ForesterUtil.NCBI_NUCCORE + URLEncoder.encode( v, ForesterConstants.UTF8 );
-                    }
+                    uri_str = ForesterUtil.NCBI_GI + URLEncoder.encode( v, ForesterConstants.UTF8 );
                 }
                 catch ( final UnsupportedEncodingException e ) {
                     showErrorMessage( tp, e.toString() );
@@ -1040,8 +1028,9 @@ public final class AptxUtil {
                                                      final boolean phyloxml_validate_against_xsd,
                                                      final boolean replace_underscores,
                                                      final boolean internal_numbers_are_confidences,
-                                                     final TAXONOMY_EXTRACTION taxonomy_extraction )
-            throws FileNotFoundException, IOException {
+                                                     final TAXONOMY_EXTRACTION taxonomy_extraction,
+                                                     final boolean midpoint_reroot ) throws FileNotFoundException,
+            IOException {
         final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
         final PhylogenyParser parser;
         boolean nhx_or_nexus = false;
@@ -1070,6 +1059,12 @@ public final class AptxUtil {
                 PhylogenyMethods.transferInternalNodeNamesToConfidence( phy );
             }
         }
+        if ( midpoint_reroot ) {
+            for( final Phylogeny phy : phys ) {
+                PhylogenyMethods.midpointRoot( phy );
+                PhylogenyMethods.orderAppearance( phy.getRoot(), true, true, DESCENDANT_SORT_PRIORITY.NODE_NAME );
+            }
+        }
         return phys;
     }