phylotastic hackathon at NESCENT 120608
[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: 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 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     
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                 
67             }
68          
69             else if ( line.startsWith( "SOURCE" ) ) {
70                 if ( line.indexOf( "(" ) > 0 ) {
71                     e.setOs( DatabaseTools.extract( line, "SOURCE", "(" ) );
72                 }
73                 else {
74                     e.setOs( DatabaseTools.extract( line, "SOURCE" ) );
75                 }
76             }
77             
78         }
79         return e;
80     }
81     
82     
83     
84     public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
85         final EbiDbEntry e = new EbiDbEntry();
86         for( final String line : lines ) {
87             
88             if ( line.startsWith( "PA" ) ) {
89                 e.setPA( DatabaseTools.extract( line, "PA" ) );
90             }
91             else if ( line.startsWith( "DE" ) ) {
92                 // if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
93                 e.setDe( DatabaseTools.extract( line, "DE" ) );
94                 //}
95             }
96             //  else if ( line.startsWith( "GN" ) ) {
97             //      if ( ( line.indexOf( "Name=" ) > 0 ) ) {
98             //          e.setSymbol( extract( line, "Name=", ";" ) );
99             //      }
100             //  }
101             else if ( line.startsWith( "OS" ) ) {
102                 if ( line.indexOf( "(" ) > 0 ) {
103                     e.setOs( DatabaseTools.extract( line, "OS", "(" ) );
104                 }
105                 else {
106                     e.setOs( DatabaseTools.extract( line, "OS" ) );
107                 }
108             }
109             else if ( line.startsWith( "OX" ) ) {
110                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
111                     e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
112                 }
113             }
114         }
115         return e;
116     }
117
118     @Override
119     public String getAccession() {
120         return _pa;
121     }
122
123     private void setPA( final String pa ) {
124         if ( _pa == null ) {
125             _pa = pa;
126         }
127     }
128
129     @Override
130     public String getSequenceName() {
131         return _de;
132     }
133
134     private void setDe( final String rec_name ) {
135         if ( _de == null ) {
136             _de = rec_name;
137         }
138     }
139
140     @Override
141     public String getTaxonomyScientificName() {
142         return _os;
143     }
144
145     private void setOs( final String os ) {
146         if ( _os == null ) {
147             _os = os;
148         }
149     }
150
151     @Override
152     public String getTaxonomyIdentifier() {
153         return _tax_id;
154     }
155
156     private void setTaxId( final String tax_id ) {
157         if ( _tax_id == null ) {
158             _tax_id = tax_id;
159         }
160     }
161
162     @Override
163     public String getSequenceSymbol() {
164         return _symbol;
165     }
166
167     private void setSymbol( final String symbol ) {
168         if ( _symbol == null ) {
169             _symbol = symbol;
170         }
171     }
172
173     @Override
174     public boolean isEmpty() {
175         return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
176                 && ForesterUtil.isEmpty( getTaxonomyScientificName() )
177                 && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil.isEmpty( getSequenceSymbol() ) );
178     }
179
180     @Override
181     public String getProvider() {
182         return _provider;
183     }
184     
185     public void setProvider( final String provider ) {
186          _provider = provider;
187     }
188 }