phylotastic hackathon at NESCENT 120606
authorcmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Wed, 6 Jun 2012 15:07:32 +0000 (15:07 +0000)
committercmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Wed, 6 Jun 2012 15:07:32 +0000 (15:07 +0000)
forester/java/src/org/forester/test/Test.java
forester/java/src/org/forester/util/SequenceIdParser.java

index 9069693..b1b35ee 100644 (file)
@@ -8924,10 +8924,112 @@ public final class Test {
     
     private static boolean testSequenceIdParsing() {
         try {
-            Identifier id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
-            if ( id == null || ForesterUtil.isEmpty( id.getValue() ) || !id.getValue().equals( "002434188_1" ) ) {
+            Identifier id = SequenceIdParser.parse( "gb_ADF31344_segmented_worms_" );
+            if ( id == null
+                 || ForesterUtil.isEmpty( id.getValue() )
+                 || ForesterUtil.isEmpty( id.getProvider() )
+                 || !id.getValue().equals( "ADF31344" )
+                 || !id.getProvider().equals( "genbank" ) ) {
+                if ( id != null ) {
+                    System.out.println( "value   =" + id.getValue() );
+                    System.out.println( "provider=" + id.getProvider() );
+                }
+                return false;
+            }
+            //
+            id = SequenceIdParser.parse( "segmented worms|gb_ADF31344" );
+            if ( id == null
+                 || ForesterUtil.isEmpty( id.getValue() )
+                 || ForesterUtil.isEmpty( id.getProvider() )
+                 || !id.getValue().equals( "ADF31344" )
+                 || !id.getProvider().equals( "genbank" ) ) {
+                if ( id != null ) {
+                    System.out.println( "value   =" + id.getValue() );
+                    System.out.println( "provider=" + id.getProvider() );
+                }
+                return false;
+            }
+            //
+            id = SequenceIdParser.parse( "segmented worms gb_ADF31344 and more" );
+            if ( id == null
+                 || ForesterUtil.isEmpty( id.getValue() )
+                 || ForesterUtil.isEmpty( id.getProvider() )
+                 || !id.getValue().equals( "ADF31344" )
+                 || !id.getProvider().equals( "genbank" ) ) {
+                if ( id != null ) {
+                    System.out.println( "value   =" + id.getValue() );
+                    System.out.println( "provider=" + id.getProvider() );
+                }
+                return false;
+            }
+           
+            // 
+            id = SequenceIdParser.parse( "gb_AAA96518_1" );
+            if ( id == null
+                 || ForesterUtil.isEmpty( id.getValue() )
+                 || ForesterUtil.isEmpty( id.getProvider() )
+                 || !id.getValue().equals( "AAA96518" )
+                 || !id.getProvider().equals( "genbank" ) ) {
+                if ( id != null ) {
+                    System.out.println( "value   =" + id.getValue() );
+                    System.out.println( "provider=" + id.getProvider() );
+                }
                 return false;
             }
+            // 
+            id = SequenceIdParser.parse( "gb_EHB07727_1_rodents_" );
+            if ( id == null
+                 || ForesterUtil.isEmpty( id.getValue() )
+                 || ForesterUtil.isEmpty( id.getProvider() )
+                 || !id.getValue().equals( "EHB07727" )
+                 || !id.getProvider().equals( "genbank" ) ) {
+                if ( id != null ) {
+                    System.out.println( "value   =" + id.getValue() );
+                    System.out.println( "provider=" + id.getProvider() );
+                }
+                return false;
+            }
+            // 
+            id = SequenceIdParser.parse( "dbj_BAF37827_1_turtles_" );
+            if ( id == null
+                 || ForesterUtil.isEmpty( id.getValue() )
+                 || ForesterUtil.isEmpty( id.getProvider() )
+                 || !id.getValue().equals( "BAF37827" )
+                 || !id.getProvider().equals( "genbank" ) ) {
+                if ( id != null ) {
+                    System.out.println( "value   =" + id.getValue() );
+                    System.out.println( "provider=" + id.getProvider() );
+                }
+                return false;
+            }
+            // 
+            id = SequenceIdParser.parse( "emb_CAA73223_1_primates_" );
+            if ( id == null
+                 || ForesterUtil.isEmpty( id.getValue() )
+                 || ForesterUtil.isEmpty( id.getProvider() )
+                 || !id.getValue().equals( "CAA73223" )
+                 || !id.getProvider().equals( "genbank" ) ) {
+                if ( id != null ) {
+                    System.out.println( "value   =" + id.getValue() );
+                    System.out.println( "provider=" + id.getProvider() );
+                }
+                return false;
+            }
+            // 
+//            id = SequenceIdParser.parse( "mites|ref_XP_002434188_1" );
+//            if ( id == null
+//                 || ForesterUtil.isEmpty( id.getValue() )
+//                 || ForesterUtil.isEmpty( id.getProvider() )
+//                 || !id.getValue().equals( "002434188" )
+//                 || !id.getProvider().equals( "genbank" ) ) {
+//                if ( id != null ) {
+//                    System.out.println( "value   =" + id.getValue() );
+//                    System.out.println( "provider=" + id.getProvider() );
+//                }
+//                return false;
+//            }
+            
+            // lcl_91970_unknown_
         }
         catch ( final Exception e ) {
             e.printStackTrace( System.out );
index b8bebe1..7486d8a 100644 (file)
 \r
 package org.forester.util;\r
 \r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
+\r
 import org.forester.phylogeny.data.Identifier;\r
+import org.forester.ws.uniprot.DatabaseTools;\r
 \r
 public final class SequenceIdParser {\r
 \r
     \r
-    // ref_XP_002434188_1_mites___ticks_\r
-    // ref_NP_001121530_1_frogs___toads_\r
+   \r
     // gb_ADF31344_1_segmented_worms_\r
     // gb_AAA96518_1\r
     // gb_EHB07727_1_rodents_\r
     // dbj_BAF37827_1_turtles_\r
     // emb_CAA73223_1_primates_\r
     // lcl_91970_unknown_\r
+    // mites|ref_XP_002434188_1\r
+    // ref_XP_002434188_1_mites___ticks_\r
+    // ref_NP_001121530_1_frogs___toads_\r
+    \r
+    //The format for GenBank Accession numbers are:\r
+    //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals\r
+    //Protein:    3 letters + 5 numerals\r
+    //http://www.ncbi.nlm.nih.gov/Sequin/acc.html\r
+    private final static Pattern GENBANK_NUCLEOTIDE_AC_PATTERN_1 = Pattern\r
+                                                                         .compile( "(?:\\A|.*[^a-zA-Z0-9])([A-Z]\\d{5})(?:[^a-zA-Z0-9]|\\Z)" );\r
+    private final static Pattern GENBANK_NUCLEOTIDE_AC_PATTERN_2 = Pattern\r
+                                                                         .compile( "(?:\\A|.*[^a-zA-Z0-9])([A-Z]{2}\\d{6})(?:[^a-zA-Z0-9]|\\Z)" );\r
+    private final static Pattern GENBANK_PROTEIN_AC_PATTERN      = Pattern\r
+                                                                         .compile( "(?:\\A|.*[^a-zA-Z0-9])([A-Z]{3}\\d{5})(?:[^a-zA-Z0-9]|\\Z)" );\r
+    private final static boolean DEBUG                           = false;\r
+\r
     \r
     \r
     public final static Identifier parse( final String s ) {\r
+        String v = DatabaseTools.parseGenbankAccessor( s );\r
+        if ( !ForesterUtil.isEmpty( v ) ) {\r
+            return new Identifier( v, "genbank" );\r
+        }\r
         \r
         return null;\r
     }\r
     \r
     \r
+    \r
+    \r
+    \r
     private SequenceIdParser() {\r
         // Hiding the constructor.\r
     }\r