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.sequence.BasicSequence;
40 import org.forester.sequence.MolecularSequence;
41 import org.forester.util.ForesterUtil;
43 public final class UniProtEntry implements SequenceDatabaseEntry {
45 public final static Pattern BindingDB_PATTERN = Pattern.compile( "BindingDB;\\s+([0-9A-Z]+);" );
46 public final static Pattern CTD_PATTERN = Pattern.compile( "CTD;\\s+(\\d+);" );
47 public final static Pattern DrugBank_PATTERN = Pattern.compile( "DrugBank;\\s+([0-9A-Z]+);\\s+([^\\.]+)" );
48 public final static Pattern GO_PATTERN = Pattern.compile( "GO;\\s+(GO:\\d+);\\s+([PFC]):([^;]+);" );
49 public final static Pattern KEGG_PATTERN = Pattern.compile( "KEGG;\\s+([a-z]+:[0-9]+);" );
50 public final static Pattern MIM_PATTERN = Pattern.compile( "MIM;\\s+(\\d+);" );
51 public final static Pattern NextBio_PATTERN = Pattern.compile( "NextBio;\\s+(\\d+);" );
52 public final static Pattern Orphanet_PATTERN = Pattern.compile( "Orphanet;\\s+(\\d+);\\s+([^\\.]+)" );
53 public final static Pattern PDB_PATTERN = Pattern.compile( "PDB;\\s+([0-9A-Z]{4});\\s+([^;]+)" );
54 public final static Pattern PharmGKB_PATTERN = Pattern.compile( "PharmGKB;\\s+([0-9A-Z]+);" );
55 public final static Pattern Reactome_PATTERN = Pattern.compile( "Reactome;\\s+([0-9A-Z]+);\\s+([^\\.]+)" );
56 public final static Pattern HGNC_PATTERN = Pattern.compile( "HGNC;\\s+HGNC:(\\d+);" );
58 private SortedSet<Accession> _cross_references;
59 private String _gene_name;
60 private SortedSet<GoTerm> _go_terms;
62 private String _os_scientific_name;
63 private String _symbol;
64 private String _tax_id;
65 private MolecularSequence _mol_seq;
67 private UniProtEntry() {
71 public Object clone() throws CloneNotSupportedException {
72 throw new CloneNotSupportedException();
76 public String getAccession() {
81 public SortedSet<Accession> getCrossReferences() {
82 return _cross_references;
86 public String getGeneName() {
91 public SortedSet<GoTerm> getGoTerms() {
96 public String getProvider() {
101 public String getSequenceName() {
106 public String getSequenceSymbol() {
111 public String getTaxonomyIdentifier() {
116 public String getTaxonomyScientificName() {
117 return _os_scientific_name;
121 public boolean isEmpty() {
122 return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
123 && ForesterUtil.isEmpty( getTaxonomyScientificName() ) && ForesterUtil.isEmpty( getSequenceSymbol() )
124 && ForesterUtil.isEmpty( getGeneName() ) && ForesterUtil.isEmpty( getTaxonomyIdentifier() )
125 && ForesterUtil.isEmpty( getSequenceSymbol() ) && ( ( getGoTerms() == null ) || getGoTerms().isEmpty() ) && ( ( getCrossReferences() == null ) || getCrossReferences()
129 private void addCrossReference( final Accession accession ) {
130 if ( _cross_references == null ) {
131 _cross_references = new TreeSet<Accession>();
133 _cross_references.add( accession );
136 private void addGoTerm( final BasicGoTerm g ) {
137 if ( _go_terms == null ) {
138 _go_terms = new TreeSet<GoTerm>();
143 private void setAc( final String ac ) {
149 private void setMolecularSequence( final MolecularSequence mol_seq ) {
153 private void setGeneName( final String gene_name ) {
154 if ( _gene_name == null ) {
155 _gene_name = gene_name;
159 private void setOsScientificName( final String os_scientific_name ) {
160 if ( _os_scientific_name == null ) {
161 _os_scientific_name = os_scientific_name;
165 private void setSequenceName( final String name ) {
166 if ( _name == null ) {
171 private void setSequenceSymbol( final String symbol ) {
175 private void setTaxId( final String tax_id ) {
176 if ( _tax_id == null ) {
181 public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
182 final UniProtEntry e = new UniProtEntry();
183 boolean saw_sq = false;
184 final StringBuffer sq_buffer = new StringBuffer();
185 boolean is_aa = false;
186 for( final String line : lines ) {
187 //System.out.println( line );
188 if ( line.startsWith( "AC" ) ) {
189 e.setAc( SequenceDbWsTools.extractFromTo( line, "AC", ";" ) );
191 else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceName() ) ) {
192 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
193 e.setSequenceName( SequenceDbWsTools.extractFromTo( line, "Full=", ";" ) );
195 else if ( ( line.indexOf( "SubName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
196 e.setSequenceName( SequenceDbWsTools.extractFromTo( line, "Full=", ";" ) );
199 else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceSymbol() ) ) {
200 if ( line.indexOf( "Short=" ) > 0 ) {
201 e.setSequenceSymbol( SequenceDbWsTools.extractFromTo( line, "Short=", ";" ) );
204 else if ( line.startsWith( "GN" ) && ForesterUtil.isEmpty( e.getGeneName() ) ) {
205 if ( line.indexOf( "Name=" ) > 0 ) {
206 e.setGeneName( SequenceDbWsTools.extractFromTo( line, "Name=", ";" ) );
209 else if ( line.startsWith( "DR" ) ) {
210 if ( line.indexOf( "GO;" ) > 0 ) {
211 final Matcher m = GO_PATTERN.matcher( line );
213 final String id = m.group( 1 );
214 final String ns_str = m.group( 2 );
215 final String desc = m.group( 3 );
216 String gns = GoNameSpace.BIOLOGICAL_PROCESS_STR;
217 if ( ns_str.equals( "F" ) ) {
218 gns = GoNameSpace.MOLECULAR_FUNCTION_STR;
220 else if ( ns_str.equals( "C" ) ) {
221 gns = GoNameSpace.CELLULAR_COMPONENT_STR;
223 e.addGoTerm( new BasicGoTerm( id, desc, gns, false ) );
226 else if ( line.indexOf( "PDB;" ) > 0 ) {
227 final Matcher m = PDB_PATTERN.matcher( line );
229 e.addCrossReference( new Accession( m.group( 1 ), "PDB", m.group( 2 ) ) );
232 else if ( line.indexOf( "KEGG;" ) > 0 ) {
233 final Matcher m = KEGG_PATTERN.matcher( line );
235 e.addCrossReference( new Accession( m.group( 1 ), "KEGG" ) );
238 else if ( line.indexOf( "CTD;" ) > 0 ) {
239 final Matcher m = CTD_PATTERN.matcher( line );
241 e.addCrossReference( new Accession( m.group( 1 ), "CTD" ) );
244 else if ( line.indexOf( "MIM;" ) > 0 ) {
245 final Matcher m = MIM_PATTERN.matcher( line );
247 e.addCrossReference( new Accession( m.group( 1 ), "MIM" ) );
250 else if ( line.indexOf( "Orphanet;" ) > 0 ) {
251 final Matcher m = Orphanet_PATTERN.matcher( line );
253 e.addCrossReference( new Accession( m.group( 1 ), "Orphanet", m.group( 2 ) ) );
256 else if ( line.indexOf( "PharmGKB;" ) > 0 ) {
257 final Matcher m = PharmGKB_PATTERN.matcher( line );
259 e.addCrossReference( new Accession( m.group( 1 ), "PharmGKB" ) );
262 else if ( line.indexOf( "BindingDB;" ) > 0 ) {
263 final Matcher m = BindingDB_PATTERN.matcher( line );
265 e.addCrossReference( new Accession( m.group( 1 ), "BindingDB" ) );
268 else if ( line.indexOf( "DrugBank;" ) > 0 ) {
269 final Matcher m = DrugBank_PATTERN.matcher( line );
271 e.addCrossReference( new Accession( m.group( 1 ), "DrugBank", m.group( 2 ) ) );
274 else if ( line.indexOf( "NextBio;" ) > 0 ) {
275 final Matcher m = NextBio_PATTERN.matcher( line );
277 e.addCrossReference( new Accession( m.group( 1 ), "NextBio" ) );
280 else if ( line.indexOf( "Reactome;" ) > 0 ) {
281 final Matcher m = Reactome_PATTERN.matcher( line );
283 e.addCrossReference( new Accession( m.group( 1 ), "Reactome", m.group( 2 ) ) );
286 else if ( line.indexOf( "HGNC;" ) > 0 ) {
287 final Matcher m = HGNC_PATTERN.matcher( line );
289 e.addCrossReference( new Accession( m.group( 1 ), "HGNC" ) );
293 else if ( line.startsWith( "OS" ) ) {
294 if ( line.indexOf( "(" ) > 0 ) {
295 e.setOsScientificName( SequenceDbWsTools.extractFromTo( line, "OS", "(" ) );
298 e.setOsScientificName( SequenceDbWsTools.extractFromTo( line, "OS", "." ) );
301 else if ( line.startsWith( "OX" ) ) {
302 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
303 e.setTaxId( SequenceDbWsTools.extractFromTo( line, "NCBI_TaxID=", ";" ) );
306 else if ( line.startsWith( "SQ" ) ) {
308 if ( line.contains( "AA;" ) ) {
312 else if ( saw_sq && line.startsWith( " " ) ) {
313 sq_buffer.append( line.replaceAll( "\\s+", "" ) );
316 if ( ( sq_buffer.length() > 0 ) && is_aa ) {
317 e.setMolecularSequence( BasicSequence.createAaSequence( e.getAccession(), sq_buffer.toString() ) );
323 public SortedSet<Annotation> getAnnotations() {
328 public String getMap() {
333 public String getChromosome() {
338 public MolecularSequence getMolecularSequence() {