inprogress
[jalview.git] / forester / java / src / org / forester / ws / seqdb / EbiDbEntry.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: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.ws.seqdb;
27
28 import java.util.List;
29
30 import org.forester.go.GoTerm;
31 import org.forester.phylogeny.data.Accession;
32 import org.forester.util.ForesterUtil;
33
34 public final class EbiDbEntry implements SequenceDatabaseEntry {
35
36     //http://www.ebi.ac.uk/Tools/dbfetch/dbfetch/emb/AAR37336/
37     private String _pa;
38     private String _de;
39     private String _os;
40     private String _tax_id;
41     private String _symbol;
42     private String _provider;
43
44     private EbiDbEntry() {
45     }
46
47     @Override
48     public Object clone() throws CloneNotSupportedException {
49         throw new CloneNotSupportedException();
50     }
51
52     public static SequenceDatabaseEntry createInstanceFromPlainTextForRefSeq( final List<String> lines ) {
53         final EbiDbEntry e = new EbiDbEntry();
54         for( final String line : lines ) {
55             //  System.out.println( "-" + line );
56             if ( line.startsWith( "ACCESSION" ) ) {
57                 e.setPA( DatabaseTools.extract( line, "ACCESSION" ) );
58             }
59             else if ( line.startsWith( "DEFINITION" ) ) {
60                 if ( line.indexOf( "[" ) > 0 ) {
61                     e.setDe( DatabaseTools.extract( line, "DEFINITION", "[" ) );
62                 }
63                 else if ( line.indexOf( "." ) > 0 ) {
64                     e.setDe( DatabaseTools.extract( line, "DEFINITION", "." ) );
65                 }
66                 else {
67                     e.setDe( DatabaseTools.extract( line, "DEFINITION" ) );
68                 }
69             }
70             else if ( line.startsWith( "SOURCE" ) ) {
71                 if ( line.indexOf( "(" ) > 0 ) {
72                     e.setOs( DatabaseTools.extract( line, "SOURCE", "(" ) );
73                 }
74                 else {
75                     e.setOs( DatabaseTools.extract( line, "SOURCE" ) );
76                 }
77             }
78         }
79         return e;
80     }
81
82     public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
83         final EbiDbEntry e = new EbiDbEntry();
84         for( final String line : lines ) {
85             if ( line.startsWith( "PA" ) ) {
86                 e.setPA( DatabaseTools.extract( line, "PA" ) );
87             }
88             else if ( line.startsWith( "DE" ) ) {
89                 e.setDe( DatabaseTools.extract( line, "DE" ) );
90             }
91             else if ( line.startsWith( "OS" ) ) {
92                 if ( line.indexOf( "(" ) > 0 ) {
93                     e.setOs( DatabaseTools.extract( line, "OS", "(" ) );
94                 }
95                 else {
96                     e.setOs( DatabaseTools.extract( line, "OS" ) );
97                 }
98             }
99             else if ( line.startsWith( "OX" ) ) {
100                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
101                     e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
102                 }
103             }
104         }
105         return e;
106     }
107
108     @Override
109     public String getAccession() {
110         return _pa;
111     }
112
113     private void setPA( final String pa ) {
114         if ( _pa == null ) {
115             _pa = pa;
116         }
117     }
118
119     @Override
120     public String getSequenceName() {
121         return _de;
122     }
123
124     private void setDe( final String rec_name ) {
125         if ( _de == null ) {
126             _de = rec_name;
127         }
128     }
129
130     @Override
131     public String getTaxonomyScientificName() {
132         return _os;
133     }
134
135     private void setOs( final String os ) {
136         if ( _os == null ) {
137             _os = os;
138         }
139     }
140
141     @Override
142     public String getTaxonomyIdentifier() {
143         return _tax_id;
144     }
145
146     private void setTaxId( final String tax_id ) {
147         if ( _tax_id == null ) {
148             _tax_id = tax_id;
149         }
150     }
151
152     @Override
153     public String getSequenceSymbol() {
154         return _symbol;
155     }
156
157     @Override
158     public boolean isEmpty() {
159         return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
160                 && ForesterUtil.isEmpty( getTaxonomyScientificName() )
161                 && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil.isEmpty( getSequenceSymbol() ) );
162     }
163
164     @Override
165     public String getProvider() {
166         return _provider;
167     }
168
169     public void setProvider( final String provider ) {
170         _provider = provider;
171     }
172
173     @Override
174     public String getGeneName() {
175         return null;
176     }
177
178     @Override
179     public List<GoTerm> getGoTerms() {
180         return null;
181     }
182
183     @Override
184     public List<Accession> getCrossReferences() {
185         return null;
186     }
187 }