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