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