7486d8a43359898f457f3f2c7aaadceccedf0325
[jalview.git] / forester / java / src / org / forester / util / SequenceIdParser.java
1 // $Id:\r
2 // FORESTER -- software libraries and applications\r
3 // for evolutionary biology research and applications.\r
4 //\r
5 // Copyright (C) 2008-2009 Christian M. Zmasek\r
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research\r
7 // Copyright (C) 2000-2001 Washington University School of Medicine\r
8 // and Howard Hughes Medical Institute\r
9 // Copyright (C) 2003-2007 Ethalinda K.S. Cannon\r
10 // All rights reserved\r
11 //\r
12 // This library is free software; you can redistribute it and/or\r
13 // modify it under the terms of the GNU Lesser General Public\r
14 // License as published by the Free Software Foundation; either\r
15 // version 2.1 of the License, or (at your option) any later version.\r
16 //\r
17 // This library is distributed in the hope that it will be useful,\r
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
20 // Lesser General Public License for more details.\r
21 //\r
22 // You should have received a copy of the GNU Lesser General Public\r
23 // License along with this library; if not, write to the Free Software\r
24 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
25 //\r
26 // Contact: phylosoft @ gmail . com\r
27 // WWW: www.phylosoft.org/forester\r
28 \r
29 package org.forester.util;\r
30 \r
31 import java.util.regex.Matcher;\r
32 import java.util.regex.Pattern;\r
33 \r
34 import org.forester.phylogeny.data.Identifier;\r
35 import org.forester.ws.uniprot.DatabaseTools;\r
36 \r
37 public final class SequenceIdParser {\r
38 \r
39     \r
40    \r
41     // gb_ADF31344_1_segmented_worms_\r
42     // gb_AAA96518_1\r
43     // gb_EHB07727_1_rodents_\r
44     // dbj_BAF37827_1_turtles_\r
45     // emb_CAA73223_1_primates_\r
46     // lcl_91970_unknown_\r
47     // mites|ref_XP_002434188_1\r
48     // ref_XP_002434188_1_mites___ticks_\r
49     // ref_NP_001121530_1_frogs___toads_\r
50     \r
51     //The format for GenBank Accession numbers are:\r
52     //Nucleotide: 1 letter + 5 numerals OR 2 letters + 6 numerals\r
53     //Protein:    3 letters + 5 numerals\r
54     //http://www.ncbi.nlm.nih.gov/Sequin/acc.html\r
55     private final static Pattern GENBANK_NUCLEOTIDE_AC_PATTERN_1 = Pattern\r
56                                                                          .compile( "(?:\\A|.*[^a-zA-Z0-9])([A-Z]\\d{5})(?:[^a-zA-Z0-9]|\\Z)" );\r
57     private final static Pattern GENBANK_NUCLEOTIDE_AC_PATTERN_2 = Pattern\r
58                                                                          .compile( "(?:\\A|.*[^a-zA-Z0-9])([A-Z]{2}\\d{6})(?:[^a-zA-Z0-9]|\\Z)" );\r
59     private final static Pattern GENBANK_PROTEIN_AC_PATTERN      = Pattern\r
60                                                                          .compile( "(?:\\A|.*[^a-zA-Z0-9])([A-Z]{3}\\d{5})(?:[^a-zA-Z0-9]|\\Z)" );\r
61     private final static boolean DEBUG                           = false;\r
62 \r
63     \r
64     \r
65     public final static Identifier parse( final String s ) {\r
66         String v = DatabaseTools.parseGenbankAccessor( s );\r
67         if ( !ForesterUtil.isEmpty( v ) ) {\r
68             return new Identifier( v, "genbank" );\r
69         }\r
70         \r
71         return null;\r
72     }\r
73     \r
74     \r
75     \r
76     \r
77     \r
78     private SequenceIdParser() {\r
79         // Hiding the constructor.\r
80     }\r
81     \r
82     \r
83     \r
84 }\r