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.regex.Matcher;
30 import java.util.regex.Pattern;
32 import org.forester.go.BasicGoTerm;
33 import org.forester.go.GoTerm;
34 import org.forester.util.ForesterUtil;
36 public final class UniProtEntry implements SequenceDatabaseEntry {
38 public final static Pattern GO_PATTERN = Pattern.compile( "GO;\\s+GO:(\\d+);\\s+([PF]):([^;]+);" );
41 private String _symbol;
42 private String _gene_name;
43 private String _os_scientific_name;
44 private String _tax_id;
46 private UniProtEntry() {
50 public Object clone() throws CloneNotSupportedException {
51 throw new CloneNotSupportedException();
54 public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
55 final UniProtEntry e = new UniProtEntry();
56 for( final String line : lines ) {
57 //System.out.println( line );
58 if ( line.startsWith( "AC" ) ) {
59 e.setAc( DatabaseTools.extract( line, "AC", ";" ) );
61 else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceName() ) ) {
62 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
63 e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
65 else if ( ( line.indexOf( "SubName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
66 e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
69 else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceSymbol() ) ) {
70 if ( line.indexOf( "Short=" ) > 0 ) {
71 e.setSequenceSymbol( DatabaseTools.extract( line, "Short=", ";" ) );
74 else if ( line.startsWith( "GN" ) && ForesterUtil.isEmpty( e.getGeneName() ) ) {
75 if ( line.indexOf( "Name=" ) > 0 ) {
76 e.setGeneName( DatabaseTools.extract( line, "Name=", ";" ) );
79 else if ( line.startsWith( "DR" ) ) {
80 if ( line.indexOf( "GO;" ) > 0 ) {
81 Matcher m = GO_PATTERN.matcher( line );
83 String n = m.group( 1 );
84 String ns_str = m.group( 2 );
85 String desc = m.group( 3 );
86 if ( ns_str.equals( "F" ) ) {
88 System.out.println( "GO:" + n + " " + desc + " " + ns );
89 GoTerm go = new BasicGoTerm( n, desc, ns, false );
90 // e.setGeneName( DatabaseTools.extract( line, "Name=", ";" ) );
94 else if ( line.startsWith( "OS" ) ) {
95 if ( line.indexOf( "(" ) > 0 ) {
96 e.setOsScientificName( DatabaseTools.extract( line, "OS", "(" ) );
99 e.setOsScientificName( DatabaseTools.extract( line, "OS", "." ) );
102 else if ( line.startsWith( "OX" ) ) {
103 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
104 e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
111 private void setSequenceSymbol( String symbol ) {
116 public String getAccession() {
120 private void setAc( final String ac ) {
127 public String getSequenceName() {
131 private void setSequenceName( final String name ) {
132 if ( _name == null ) {
138 public String getTaxonomyScientificName() {
139 return _os_scientific_name;
142 private void setOsScientificName( final String os_scientific_name ) {
143 if ( _os_scientific_name == null ) {
144 _os_scientific_name = os_scientific_name;
149 public String getTaxonomyIdentifier() {
153 private void setTaxId( final String tax_id ) {
154 if ( _tax_id == null ) {
159 private void setGeneName( final String gene_name ) {
160 if ( _gene_name == null ) {
161 _gene_name = gene_name;
166 public String getSequenceSymbol() {
171 public boolean isEmpty() {
172 return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
173 && ForesterUtil.isEmpty( getTaxonomyScientificName() ) && ForesterUtil.isEmpty( getSequenceSymbol() )
174 && ForesterUtil.isEmpty( getGeneName() ) && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil
175 .isEmpty( getSequenceSymbol() ) );
179 public String getProvider() {
184 public String getGeneName() {