inprogress
[jalview.git] / forester / java / src / org / forester / util / ForesterUtil.java
index 828d3df..c98edc0 100644 (file)
@@ -62,6 +62,7 @@ import java.util.TreeSet;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.forester.archaeopteryx.Constants;
 import org.forester.phylogeny.PhylogenyNode;
 import org.forester.phylogeny.data.Distribution;
 import org.forester.phylogeny.data.Sequence;
@@ -90,6 +91,7 @@ public final class ForesterUtil {
                                                                               .compile( "(?:\\b|_)(?:sp|tr)[\\.|\\-_=/\\\\]([A-Z][0-9][A-Z0-9]{3}[0-9])(?:\\b|_)" );
     public final static Pattern      UNIPROT_KB_PATTERN_2             = Pattern
                                                                               .compile( "\\b(?:[A-Z0-9]{2,5}|(?:[A-Z][0-9][A-Z0-9]{3}[0-9]))_(([A-Z9][A-Z]{2}[A-Z0-9]{2})|RAT|PIG|PEA)\\b" );
+    public static final String       NCBI_GI                          = "http://www.ncbi.nlm.nih.gov/protein/gi:";
     static {
         final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
         dfs.setDecimalSeparator( '.' );
@@ -145,6 +147,24 @@ public final class ForesterUtil {
         return v;
     }
 
+    public static String extractGInumber( final PhylogenyNode node ) {
+        String v = null;
+        if ( node.getNodeData().isHasSequence() ) {
+            final Sequence seq = node.getNodeData().getSequence();
+            if ( isEmpty( v ) && !isEmpty( seq.getName() ) ) {
+                v = SequenceIdParser.parseGInumber( seq.getName() );
+            }
+            if ( isEmpty( v ) && ( node.getNodeData().getSequence().getAccession() != null )
+                    && !isEmpty( seq.getAccession().getValue() ) ) {
+                v = SequenceIdParser.parseGInumber( seq.getAccession().getValue() );
+            }
+        }
+        if ( isEmpty( v ) && !isEmpty( node.getName() ) ) {
+            v = SequenceIdParser.parseGInumber( node.getName() );
+        }
+        return v;
+    }
+
     public static String extractUniProtKbProteinSeqIdentifier( final PhylogenyNode node ) {
         String upkb = null;
         if ( node.getNodeData().isHasSequence() ) {
@@ -664,8 +684,24 @@ public final class ForesterUtil {
         return isReadableFile( new File( s ) );
     }
 
-    public static boolean isWindowns() {
-        return ForesterUtil.OS_NAME.toLowerCase().indexOf( "win" ) > -1;
+    public final static boolean isWindows() {
+        try {
+            return OS_NAME.toLowerCase().indexOf( "win" ) > -1;
+        }
+        catch ( final Exception e ) {
+            ForesterUtil.printWarningMessage( Constants.PRG_NAME, "minor error: " + e );
+            return false;
+        }
+    }
+
+    public final static boolean isMac() {
+        try {
+            return OS_NAME.toLowerCase().startsWith( "mac" );
+        }
+        catch ( final Exception e ) {
+            ForesterUtil.printWarningMessage( Constants.PRG_NAME, "minor error: " + e );
+            return false;
+        }
     }
 
     final public static String isWritableFile( final File f ) {