ef44f385e6f97678baa81e6ae4be3b8f582eb8f9
[jalview.git] / forester / java / src / org / forester / ws / uniprot / 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: www.phylosoft.org/forester
25
26 package org.forester.ws.uniprot;
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
41     private EbiDbEntry() {
42     }
43
44     @Override
45     public Object clone() throws CloneNotSupportedException {
46         throw new CloneNotSupportedException();
47     }
48
49     
50     public static SequenceDatabaseEntry createInstanceForRefSeq( 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, "DEFINITIO", "[" ) );
60                 }
61                 else {
62                     e.setDe( DatabaseTools.extract( line, "DEFINITION" ) );
63                 }
64                
65                 
66             }
67          
68             else if ( line.startsWith( "SOURCE" ) ) {
69                 if ( line.indexOf( "(" ) > 0 ) {
70                     e.setOs( DatabaseTools.extract( line, "SOURCE", "(" ) );
71                 }
72                 else {
73                     e.setOs( DatabaseTools.extract( line, "SOURCE" ) );
74                 }
75             }
76             
77         }
78         return e;
79     }
80     
81     
82     
83     public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
84         final EbiDbEntry e = new EbiDbEntry();
85         for( final String line : lines ) {
86             System.out.println( "->" + line );
87             if ( line.startsWith( "PA" ) ) {
88                 e.setPA( DatabaseTools.extract( line, "PA" ) );
89             }
90             else if ( line.startsWith( "DE" ) ) {
91                 // if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
92                 e.setDe( DatabaseTools.extract( line, "DE" ) );
93                 //}
94             }
95             //  else if ( line.startsWith( "GN" ) ) {
96             //      if ( ( line.indexOf( "Name=" ) > 0 ) ) {
97             //          e.setSymbol( extract( line, "Name=", ";" ) );
98             //      }
99             //  }
100             else if ( line.startsWith( "OS" ) ) {
101                 if ( line.indexOf( "(" ) > 0 ) {
102                     e.setOs( DatabaseTools.extract( line, "OS", "(" ) );
103                 }
104                 else {
105                     e.setOs( DatabaseTools.extract( line, "OS" ) );
106                 }
107             }
108             else if ( line.startsWith( "OX" ) ) {
109                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
110                     e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
111                 }
112             }
113         }
114         return e;
115     }
116
117     @Override
118     public String getAccession() {
119         return _pa;
120     }
121
122     private void setPA( final String pa ) {
123         if ( _pa == null ) {
124             _pa = pa;
125         }
126     }
127
128     @Override
129     public String getSequenceName() {
130         return _de;
131     }
132
133     private void setDe( final String rec_name ) {
134         if ( _de == null ) {
135             _de = rec_name;
136         }
137     }
138
139     @Override
140     public String getTaxonomyScientificName() {
141         return _os;
142     }
143
144     private void setOs( final String os ) {
145         if ( _os == null ) {
146             _os = os;
147         }
148     }
149
150     @Override
151     public String getTaxonomyIdentifier() {
152         return _tax_id;
153     }
154
155     private void setTaxId( final String tax_id ) {
156         if ( _tax_id == null ) {
157             _tax_id = tax_id;
158         }
159     }
160
161     @Override
162     public String getSequenceSymbol() {
163         return _symbol;
164     }
165
166     private void setSymbol( final String symbol ) {
167         if ( _symbol == null ) {
168             _symbol = symbol;
169         }
170     }
171
172     @Override
173     public boolean isEmpty() {
174         return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
175                 && ForesterUtil.isEmpty( getTaxonomyScientificName() )
176                 && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil.isEmpty( getSequenceSymbol() ) );
177     }
178 }