From 813491b06a1cf8364202bfc803a4dcff8b89977c Mon Sep 17 00:00:00 2001 From: cmzmasek Date: Wed, 6 Jun 2012 15:07:32 +0000 Subject: [PATCH] phylotastic hackathon at NESCENT 120606 --- forester/java/src/org/forester/test/Test.java | 106 +++++++++++++++++++- .../src/org/forester/util/SequenceIdParser.java | 30 +++++- 2 files changed, 132 insertions(+), 4 deletions(-) diff --git a/forester/java/src/org/forester/test/Test.java b/forester/java/src/org/forester/test/Test.java index 9069693..b1b35ee 100644 --- a/forester/java/src/org/forester/test/Test.java +++ b/forester/java/src/org/forester/test/Test.java @@ -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 ); diff --git a/forester/java/src/org/forester/util/SequenceIdParser.java b/forester/java/src/org/forester/util/SequenceIdParser.java index b8bebe1..7486d8a 100644 --- a/forester/java/src/org/forester/util/SequenceIdParser.java +++ b/forester/java/src/org/forester/util/SequenceIdParser.java @@ -28,27 +28,53 @@ package org.forester.util; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.forester.phylogeny.data.Identifier; +import org.forester.ws.uniprot.DatabaseTools; public final class SequenceIdParser { - // ref_XP_002434188_1_mites___ticks_ - // ref_NP_001121530_1_frogs___toads_ + // gb_ADF31344_1_segmented_worms_ // gb_AAA96518_1 // gb_EHB07727_1_rodents_ // dbj_BAF37827_1_turtles_ // emb_CAA73223_1_primates_ // lcl_91970_unknown_ + // mites|ref_XP_002434188_1 + // ref_XP_002434188_1_mites___ticks_ + // ref_NP_001121530_1_frogs___toads_ + + //The format for GenBank Accession numbers are: + //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals + //Protein: 3 letters + 5 numerals + //http://www.ncbi.nlm.nih.gov/Sequin/acc.html + private final static Pattern GENBANK_NUCLEOTIDE_AC_PATTERN_1 = Pattern + .compile( "(?:\\A|.*[^a-zA-Z0-9])([A-Z]\\d{5})(?:[^a-zA-Z0-9]|\\Z)" ); + private final static Pattern GENBANK_NUCLEOTIDE_AC_PATTERN_2 = Pattern + .compile( "(?:\\A|.*[^a-zA-Z0-9])([A-Z]{2}\\d{6})(?:[^a-zA-Z0-9]|\\Z)" ); + private final static Pattern GENBANK_PROTEIN_AC_PATTERN = Pattern + .compile( "(?:\\A|.*[^a-zA-Z0-9])([A-Z]{3}\\d{5})(?:[^a-zA-Z0-9]|\\Z)" ); + private final static boolean DEBUG = false; + public final static Identifier parse( final String s ) { + String v = DatabaseTools.parseGenbankAccessor( s ); + if ( !ForesterUtil.isEmpty( v ) ) { + return new Identifier( v, "genbank" ); + } return null; } + + + private SequenceIdParser() { // Hiding the constructor. } -- 1.7.10.2