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.ArrayList;
29 import java.util.List;
30 import java.util.regex.Matcher;
31 import java.util.regex.Pattern;
33 import org.forester.go.BasicGoTerm;
34 import org.forester.go.GoNameSpace;
35 import org.forester.go.GoTerm;
36 import org.forester.phylogeny.data.Accession;
37 import org.forester.util.ForesterUtil;
39 public final class UniProtEntry implements SequenceDatabaseEntry {
41 public final static Pattern BindingDB_PATTERN = Pattern.compile( "BindingDB;\\s+([0-9A-Z]+);" );
42 public final static Pattern CTD_PATTERN = Pattern.compile( "CTD;\\s+(\\d+);" );
43 public final static Pattern DrugBank_PATTERN = Pattern.compile( "DrugBank;\\s+([0-9A-Z]+);\\s+([^\\.]+)" );
44 public final static Pattern GO_PATTERN = Pattern.compile( "GO;\\s+(GO:\\d+);\\s+([PFC]):([^;]+);" );
45 public final static Pattern KEGG_PATTERN = Pattern.compile( "KEGG;\\s+([a-z]+:[0-9]+);" );
46 public final static Pattern MIM_PATTERN = Pattern.compile( "MIM;\\s+(\\d+);" );
47 public final static Pattern NextBio_PATTERN = Pattern.compile( "NextBio;\\s+(\\d+);" );
48 public final static Pattern Orphanet_PATTERN = Pattern.compile( "Orphanet;\\s+(\\d+);\\s+([^\\.]+)" );
49 public final static Pattern PDB_PATTERN = Pattern.compile( "PDB;\\s+([0-9A-Z]{4});\\s+([^;]+)" );
50 public final static Pattern PharmGKB_PATTERN = Pattern.compile( "PharmGKB;\\s+([0-9A-Z]+);" );
51 public final static Pattern Reactome_PATTERN = Pattern.compile( "Reactome;\\s+([0-9A-Z]+);\\s+([^\\.]+)" );
53 private ArrayList<Accession> _cross_references;
54 private String _gene_name;
55 private List<GoTerm> _go_terms;
57 private String _os_scientific_name;
58 private String _symbol;
59 private String _tax_id;
61 private UniProtEntry() {
65 public Object clone() throws CloneNotSupportedException {
66 throw new CloneNotSupportedException();
70 public String getAccession() {
75 public List<Accession> getCrossReferences() {
76 return _cross_references;
80 public String getGeneName() {
85 public List<GoTerm> getGoTerms() {
90 public String getProvider() {
95 public String getSequenceName() {
100 public String getSequenceSymbol() {
105 public String getTaxonomyIdentifier() {
110 public String getTaxonomyScientificName() {
111 return _os_scientific_name;
115 public boolean isEmpty() {
116 return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
117 && ForesterUtil.isEmpty( getTaxonomyScientificName() ) && ForesterUtil.isEmpty( getSequenceSymbol() )
118 && ForesterUtil.isEmpty( getGeneName() ) && ForesterUtil.isEmpty( getTaxonomyIdentifier() )
119 && ForesterUtil.isEmpty( getSequenceSymbol() ) && ( ( getGoTerms() == null ) || getGoTerms().isEmpty() ) && ( ( getCrossReferences() == null ) || getCrossReferences()
123 private void addCrossReference( final Accession accession ) {
124 if ( _cross_references == null ) {
125 _cross_references = new ArrayList<Accession>();
127 System.out.println( "XREF ADDED: " + accession );
128 _cross_references.add( accession );
131 private void addGoTerm( final BasicGoTerm g ) {
132 if ( _go_terms == null ) {
133 _go_terms = new ArrayList<GoTerm>();
135 System.out.println( "GOTERM ADDED: " + g );
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( DatabaseTools.extract( 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( DatabaseTools.extract( line, "Full=", ";" ) );
184 else if ( ( line.indexOf( "SubName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
185 e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
188 else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceSymbol() ) ) {
189 if ( line.indexOf( "Short=" ) > 0 ) {
190 e.setSequenceSymbol( DatabaseTools.extract( line, "Short=", ";" ) );
193 else if ( line.startsWith( "GN" ) && ForesterUtil.isEmpty( e.getGeneName() ) ) {
194 if ( line.indexOf( "Name=" ) > 0 ) {
195 e.setGeneName( DatabaseTools.extract( 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 System.out.println( "GO:" + id + " " + desc + " " + ns_str );
213 e.addGoTerm( new BasicGoTerm( id, desc, gns, false ) );
216 else if ( line.indexOf( "PDB;" ) > 0 ) {
217 final Matcher m = PDB_PATTERN.matcher( line );
219 e.addCrossReference( new Accession( m.group( 1 ), "PDB", m.group( 2 ) ) );
222 else if ( line.indexOf( "KEGG;" ) > 0 ) {
223 final Matcher m = KEGG_PATTERN.matcher( line );
225 e.addCrossReference( new Accession( m.group( 1 ), "KEGG" ) );
228 else if ( line.indexOf( "CTD;" ) > 0 ) {
229 final Matcher m = CTD_PATTERN.matcher( line );
231 e.addCrossReference( new Accession( m.group( 1 ), "CTD" ) );
234 else if ( line.indexOf( "MIM;" ) > 0 ) {
235 final Matcher m = MIM_PATTERN.matcher( line );
237 e.addCrossReference( new Accession( m.group( 1 ), "MIM" ) );
240 else if ( line.indexOf( "Orphanet;" ) > 0 ) {
241 final Matcher m = Orphanet_PATTERN.matcher( line );
243 e.addCrossReference( new Accession( m.group( 1 ), "Orphanet", m.group( 2 ) ) );
246 else if ( line.indexOf( "PharmGKB;" ) > 0 ) {
247 final Matcher m = PharmGKB_PATTERN.matcher( line );
249 e.addCrossReference( new Accession( m.group( 1 ), "PharmGKB" ) );
252 else if ( line.indexOf( "BindingDB;" ) > 0 ) {
253 final Matcher m = BindingDB_PATTERN.matcher( line );
255 e.addCrossReference( new Accession( m.group( 1 ), "BindingDB" ) );
258 else if ( line.indexOf( "DrugBank;" ) > 0 ) {
259 final Matcher m = DrugBank_PATTERN.matcher( line );
261 e.addCrossReference( new Accession( m.group( 1 ), "DrugBank", m.group( 2 ) ) );
264 else if ( line.indexOf( "NextBio;" ) > 0 ) {
265 final Matcher m = NextBio_PATTERN.matcher( line );
267 e.addCrossReference( new Accession( m.group( 1 ), "NextBio" ) );
270 else if ( line.indexOf( "Reactome;" ) > 0 ) {
271 final Matcher m = Reactome_PATTERN.matcher( line );
273 e.addCrossReference( new Accession( m.group( 1 ), "Reactome", m.group( 2 ) ) );
277 else if ( line.startsWith( "OS" ) ) {
278 if ( line.indexOf( "(" ) > 0 ) {
279 e.setOsScientificName( DatabaseTools.extract( line, "OS", "(" ) );
282 e.setOsScientificName( DatabaseTools.extract( line, "OS", "." ) );
285 else if ( line.startsWith( "OX" ) ) {
286 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
287 e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );