fc850377ab99dfefd56c5bcee1513475b5db9806
[jalview.git] / forester / java / src / org / forester / ws / seqdb / UniProtEntry.java
1 // $Id:
2 // forester -- software libraries and applications
3 // for genomics and evolutionary biology research.
4 //
5 // Copyright (C) 2010 Christian M Zmasek
6 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
7 // All rights reserved
8 //
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.
13 //
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.
18 //
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
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
25
26 package org.forester.ws.seqdb;
27
28 import java.util.List;
29
30 import org.forester.util.ForesterUtil;
31
32 public final class UniProtEntry implements SequenceDatabaseEntry {
33
34     private String _ac;
35     private String _rec_name;
36     private String _os_scientific_name;
37     private String _tax_id;
38     private String _symbol;
39
40     private UniProtEntry() {
41     }
42
43     @Override
44     public Object clone() throws CloneNotSupportedException {
45         throw new CloneNotSupportedException();
46     }
47
48     public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
49         final UniProtEntry e = new UniProtEntry();
50         for( final String line : lines ) {
51             if ( line.startsWith( "AC" ) ) {
52                 e.setAc( DatabaseTools.extract( line, "AC", ";" ) );
53             }
54             else if ( line.startsWith( "DE" ) ) {
55                 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
56                     e.setRecName( DatabaseTools.extract( line, "Full=", ";" ) );
57                 }
58             }
59             else if ( line.startsWith( "GN" ) ) {
60                 if ( ( line.indexOf( "Name=" ) > 0 ) ) {
61                     e.setSymbol( DatabaseTools.extract( line, "Name=", ";" ) );
62                 }
63             }
64             else if ( line.startsWith( "OS" ) ) {
65                 if ( line.indexOf( "(" ) > 0 ) {
66                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "(" ) );
67                 }
68                 else {
69                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "." ) );
70                 }
71             }
72             else if ( line.startsWith( "OX" ) ) {
73                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
74                     e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
75                 }
76             }
77         }
78         return e;
79     }
80
81     @Override
82     public String getAccession() {
83         return _ac;
84     }
85
86     private void setAc( final String ac ) {
87         if ( _ac == null ) {
88             _ac = ac;
89         }
90     }
91
92     @Override
93     public String getSequenceName() {
94         return _rec_name;
95     }
96
97     private void setRecName( final String rec_name ) {
98         if ( _rec_name == null ) {
99             _rec_name = rec_name;
100         }
101     }
102
103     @Override
104     public String getTaxonomyScientificName() {
105         return _os_scientific_name;
106     }
107
108     private void setOsScientificName( final String os_scientific_name ) {
109         if ( _os_scientific_name == null ) {
110             _os_scientific_name = os_scientific_name;
111         }
112     }
113
114     @Override
115     public String getTaxonomyIdentifier() {
116         return _tax_id;
117     }
118
119     private void setTaxId( final String tax_id ) {
120         if ( _tax_id == null ) {
121             _tax_id = tax_id;
122         }
123     }
124
125     @Override
126     public String getSequenceSymbol() {
127         return _symbol;
128     }
129
130     private void setSymbol( final String symbol ) {
131         if ( _symbol == null ) {
132             _symbol = symbol;
133         }
134     }
135
136     @Override
137     public boolean isEmpty() {
138         return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
139                 && ForesterUtil.isEmpty( getTaxonomyScientificName() )
140                 && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil.isEmpty( getSequenceSymbol() ) );
141     }
142
143     @Override
144     public String getProvider() {
145         return "uniprot";
146     }
147 }