2 // forester -- software libraries and applications
3 // for genomics and evolutionary biology research.
5 // Copyright (C) 2010 Christian M Zmasek
6 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 // Contact: phylosoft @ gmail . com
24 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.ws.seqdb;
28 import java.util.List;
29 import java.util.SortedSet;
30 import java.util.TreeSet;
31 import java.util.regex.Matcher;
32 import java.util.regex.Pattern;
34 import org.forester.go.BasicGoTerm;
35 import org.forester.go.GoNameSpace;
36 import org.forester.go.GoTerm;
37 import org.forester.phylogeny.data.Accession;
38 import org.forester.phylogeny.data.Annotation;
39 import org.forester.util.ForesterUtil;
41 public final class UniProtEntry implements SequenceDatabaseEntry {
43 public final static Pattern BindingDB_PATTERN = Pattern.compile( "BindingDB;\\s+([0-9A-Z]+);" );
44 public final static Pattern CTD_PATTERN = Pattern.compile( "CTD;\\s+(\\d+);" );
45 public final static Pattern DrugBank_PATTERN = Pattern.compile( "DrugBank;\\s+([0-9A-Z]+);\\s+([^\\.]+)" );
46 public final static Pattern GO_PATTERN = Pattern.compile( "GO;\\s+(GO:\\d+);\\s+([PFC]):([^;]+);" );
47 public final static Pattern KEGG_PATTERN = Pattern.compile( "KEGG;\\s+([a-z]+:[0-9]+);" );
48 public final static Pattern MIM_PATTERN = Pattern.compile( "MIM;\\s+(\\d+);" );
49 public final static Pattern NextBio_PATTERN = Pattern.compile( "NextBio;\\s+(\\d+);" );
50 public final static Pattern Orphanet_PATTERN = Pattern.compile( "Orphanet;\\s+(\\d+);\\s+([^\\.]+)" );
51 public final static Pattern PDB_PATTERN = Pattern.compile( "PDB;\\s+([0-9A-Z]{4});\\s+([^;]+)" );
52 public final static Pattern PharmGKB_PATTERN = Pattern.compile( "PharmGKB;\\s+([0-9A-Z]+);" );
53 public final static Pattern Reactome_PATTERN = Pattern.compile( "Reactome;\\s+([0-9A-Z]+);\\s+([^\\.]+)" );
55 private SortedSet<Accession> _cross_references;
56 private String _gene_name;
57 private SortedSet<GoTerm> _go_terms;
59 private String _os_scientific_name;
60 private String _symbol;
61 private String _tax_id;
63 private UniProtEntry() {
67 public Object clone() throws CloneNotSupportedException {
68 throw new CloneNotSupportedException();
72 public String getAccession() {
77 public SortedSet<Accession> getCrossReferences() {
78 return _cross_references;
82 public String getGeneName() {
87 public SortedSet<GoTerm> getGoTerms() {
92 public String getProvider() {
97 public String getSequenceName() {
102 public String getSequenceSymbol() {
107 public String getTaxonomyIdentifier() {
112 public String getTaxonomyScientificName() {
113 return _os_scientific_name;
117 public boolean isEmpty() {
118 return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
119 && ForesterUtil.isEmpty( getTaxonomyScientificName() ) && ForesterUtil.isEmpty( getSequenceSymbol() )
120 && ForesterUtil.isEmpty( getGeneName() ) && ForesterUtil.isEmpty( getTaxonomyIdentifier() )
121 && ForesterUtil.isEmpty( getSequenceSymbol() ) && ( ( getGoTerms() == null ) || getGoTerms().isEmpty() ) && ( ( getCrossReferences() == null ) || getCrossReferences()
125 private void addCrossReference( final Accession accession ) {
126 if ( _cross_references == null ) {
127 _cross_references = new TreeSet<Accession>();
129 _cross_references.add( accession );
132 private void addGoTerm( final BasicGoTerm g ) {
133 if ( _go_terms == null ) {
134 _go_terms = new TreeSet<GoTerm>();
139 private void setAc( final String ac ) {
145 private void setGeneName( final String gene_name ) {
146 if ( _gene_name == null ) {
147 _gene_name = gene_name;
151 private void setOsScientificName( final String os_scientific_name ) {
152 if ( _os_scientific_name == null ) {
153 _os_scientific_name = os_scientific_name;
157 private void setSequenceName( final String name ) {
158 if ( _name == null ) {
163 private void setSequenceSymbol( final String symbol ) {
167 private void setTaxId( final String tax_id ) {
168 if ( _tax_id == null ) {
173 public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
174 final UniProtEntry e = new UniProtEntry();
175 for( final String line : lines ) {
176 //System.out.println( line );
177 if ( line.startsWith( "AC" ) ) {
178 e.setAc( SequenceDbWsTools.extractFromTo( line, "AC", ";" ) );
180 else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceName() ) ) {
181 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
182 e.setSequenceName( SequenceDbWsTools.extractFromTo( line, "Full=", ";" ) );
184 else if ( ( line.indexOf( "SubName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
185 e.setSequenceName( SequenceDbWsTools.extractFromTo( line, "Full=", ";" ) );
188 else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceSymbol() ) ) {
189 if ( line.indexOf( "Short=" ) > 0 ) {
190 e.setSequenceSymbol( SequenceDbWsTools.extractFromTo( line, "Short=", ";" ) );
193 else if ( line.startsWith( "GN" ) && ForesterUtil.isEmpty( e.getGeneName() ) ) {
194 if ( line.indexOf( "Name=" ) > 0 ) {
195 e.setGeneName( SequenceDbWsTools.extractFromTo( line, "Name=", ";" ) );
198 else if ( line.startsWith( "DR" ) ) {
199 if ( line.indexOf( "GO;" ) > 0 ) {
200 final Matcher m = GO_PATTERN.matcher( line );
202 final String id = m.group( 1 );
203 final String ns_str = m.group( 2 );
204 final String desc = m.group( 3 );
205 String gns = GoNameSpace.BIOLOGICAL_PROCESS_STR;
206 if ( ns_str.equals( "F" ) ) {
207 gns = GoNameSpace.MOLECULAR_FUNCTION_STR;
209 else if ( ns_str.equals( "C" ) ) {
210 gns = GoNameSpace.CELLULAR_COMPONENT_STR;
212 e.addGoTerm( new BasicGoTerm( id, desc, gns, false ) );
215 else if ( line.indexOf( "PDB;" ) > 0 ) {
216 final Matcher m = PDB_PATTERN.matcher( line );
218 e.addCrossReference( new Accession( m.group( 1 ), "PDB", m.group( 2 ) ) );
221 else if ( line.indexOf( "KEGG;" ) > 0 ) {
222 final Matcher m = KEGG_PATTERN.matcher( line );
224 e.addCrossReference( new Accession( m.group( 1 ), "KEGG" ) );
227 else if ( line.indexOf( "CTD;" ) > 0 ) {
228 final Matcher m = CTD_PATTERN.matcher( line );
230 e.addCrossReference( new Accession( m.group( 1 ), "CTD" ) );
233 else if ( line.indexOf( "MIM;" ) > 0 ) {
234 final Matcher m = MIM_PATTERN.matcher( line );
236 e.addCrossReference( new Accession( m.group( 1 ), "MIM" ) );
239 else if ( line.indexOf( "Orphanet;" ) > 0 ) {
240 final Matcher m = Orphanet_PATTERN.matcher( line );
242 e.addCrossReference( new Accession( m.group( 1 ), "Orphanet", m.group( 2 ) ) );
245 else if ( line.indexOf( "PharmGKB;" ) > 0 ) {
246 final Matcher m = PharmGKB_PATTERN.matcher( line );
248 e.addCrossReference( new Accession( m.group( 1 ), "PharmGKB" ) );
251 else if ( line.indexOf( "BindingDB;" ) > 0 ) {
252 final Matcher m = BindingDB_PATTERN.matcher( line );
254 e.addCrossReference( new Accession( m.group( 1 ), "BindingDB" ) );
257 else if ( line.indexOf( "DrugBank;" ) > 0 ) {
258 final Matcher m = DrugBank_PATTERN.matcher( line );
260 e.addCrossReference( new Accession( m.group( 1 ), "DrugBank", m.group( 2 ) ) );
263 else if ( line.indexOf( "NextBio;" ) > 0 ) {
264 final Matcher m = NextBio_PATTERN.matcher( line );
266 e.addCrossReference( new Accession( m.group( 1 ), "NextBio" ) );
269 else if ( line.indexOf( "Reactome;" ) > 0 ) {
270 final Matcher m = Reactome_PATTERN.matcher( line );
272 e.addCrossReference( new Accession( m.group( 1 ), "Reactome", m.group( 2 ) ) );
276 else if ( line.startsWith( "OS" ) ) {
277 if ( line.indexOf( "(" ) > 0 ) {
278 e.setOsScientificName( SequenceDbWsTools.extractFromTo( line, "OS", "(" ) );
281 e.setOsScientificName( SequenceDbWsTools.extractFromTo( line, "OS", "." ) );
284 else if ( line.startsWith( "OX" ) ) {
285 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
286 e.setTaxId( SequenceDbWsTools.extractFromTo( line, "NCBI_TaxID=", ";" ) );
294 public SortedSet<Annotation> getAnnotations() {
299 public String getMap( ) {
305 public String getChromosome( ) {