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.util.ForesterUtil;
38 public final class UniProtEntry implements SequenceDatabaseEntry {
40 public final static Pattern GO_PATTERN = Pattern.compile( "GO;\\s+(GO:\\d+);\\s+([PF]):([^;]+);" );
43 private String _symbol;
44 private String _gene_name;
45 private String _os_scientific_name;
46 private String _tax_id;
47 private List<GoTerm> _go_terms;
49 private UniProtEntry() {
53 public Object clone() throws CloneNotSupportedException {
54 throw new CloneNotSupportedException();
57 public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
58 final UniProtEntry e = new UniProtEntry();
59 for( final String line : lines ) {
60 //System.out.println( line );
61 if ( line.startsWith( "AC" ) ) {
62 e.setAc( DatabaseTools.extract( line, "AC", ";" ) );
64 else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceName() ) ) {
65 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
66 e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
68 else if ( ( line.indexOf( "SubName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
69 e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
72 else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceSymbol() ) ) {
73 if ( line.indexOf( "Short=" ) > 0 ) {
74 e.setSequenceSymbol( DatabaseTools.extract( line, "Short=", ";" ) );
77 else if ( line.startsWith( "GN" ) && ForesterUtil.isEmpty( e.getGeneName() ) ) {
78 if ( line.indexOf( "Name=" ) > 0 ) {
79 e.setGeneName( DatabaseTools.extract( line, "Name=", ";" ) );
82 else if ( line.startsWith( "DR" ) ) {
83 if ( line.indexOf( "GO;" ) > 0 ) {
84 Matcher m = GO_PATTERN.matcher( line );
86 String id = m.group( 1 );
87 String ns_str = m.group( 2 );
88 String desc = m.group( 3 );
89 String gns = GoNameSpace.BIOLOGICAL_PROCESS_STR;
90 if ( ns_str.equals( "F" ) ) {
91 gns = GoNameSpace.MOLECULAR_FUNCTION_STR;
94 System.out.println( "GO:" + id + " " + desc + " " + ns_str );
96 e.addGoTerm( new BasicGoTerm( id, desc, gns, false ) );
100 else if ( line.startsWith( "OS" ) ) {
101 if ( line.indexOf( "(" ) > 0 ) {
102 e.setOsScientificName( DatabaseTools.extract( line, "OS", "(" ) );
105 e.setOsScientificName( DatabaseTools.extract( line, "OS", "." ) );
108 else if ( line.startsWith( "OX" ) ) {
109 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
110 e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
117 private void addGoTerm( BasicGoTerm g ) {
118 if ( _go_terms == null ) {
119 _go_terms = new ArrayList<GoTerm>();
125 private void setSequenceSymbol( String symbol ) {
130 public String getAccession() {
134 private void setAc( final String ac ) {
141 public String getSequenceName() {
145 private void setSequenceName( final String name ) {
146 if ( _name == null ) {
152 public String getTaxonomyScientificName() {
153 return _os_scientific_name;
156 private void setOsScientificName( final String os_scientific_name ) {
157 if ( _os_scientific_name == null ) {
158 _os_scientific_name = os_scientific_name;
163 public String getTaxonomyIdentifier() {
167 private void setTaxId( final String tax_id ) {
168 if ( _tax_id == null ) {
173 private void setGeneName( final String gene_name ) {
174 if ( _gene_name == null ) {
175 _gene_name = gene_name;
180 public List<GoTerm> getGoTerms() {
186 public String getSequenceSymbol() {
191 public boolean isEmpty() {
192 return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
193 && ForesterUtil.isEmpty( getTaxonomyScientificName() ) && ForesterUtil.isEmpty( getSequenceSymbol() )
194 && ForesterUtil.isEmpty( getGeneName() ) && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil
195 .isEmpty( getSequenceSymbol() ) && ( getGoTerms() == null || getGoTerms().isEmpty() ) );
199 public String getProvider() {
204 public String getGeneName() {