in progress
[jalview.git] / forester / java / src / org / forester / ws / uniprot / UniProtEntry.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 public final class UniProtEntry implements SequenceDatabaseEntry {
31
32     private String _ac;
33     private String _rec_name;
34     private String _os_scientific_name;
35     private String _tax_id;
36     private String _symbol;
37
38     private UniProtEntry() {
39     }
40
41     public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
42         final UniProtEntry e = new UniProtEntry();
43         for( final String line : lines ) {
44             if ( line.startsWith( "AC" ) ) {
45                 e.setAc( extract( line, "AC", ";" ) );
46             }
47             else if ( line.startsWith( "DE" ) ) {
48                 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
49                     e.setRecName( extract( line, "Full=", ";" ) );
50                 }
51             }
52             else if ( line.startsWith( "GN" ) ) {
53                 if ( ( line.indexOf( "Name=" ) > 0 ) ) {
54                     e.setSymbol( extract( line, "Name=", ";" ) );
55                 }
56             }
57             else if ( line.startsWith( "OS" ) ) {
58                 if ( line.indexOf( "(" ) > 0 ) {
59                     e.setOsScientificName( extract( line, "OS", "(" ) );
60                 }
61                 else {
62                     e.setOsScientificName( extract( line, "OS", "." ) );
63                 }
64             }
65             else if ( line.startsWith( "OX" ) ) {
66                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
67                     e.setTaxId( extract( line, "NCBI_TaxID=", ";" ) );
68                 }
69             }
70         }
71         return e;
72     }
73
74     private static String extract( final String target, final String a, final String b ) {
75         final int i_a = target.indexOf( a );
76         final int i_b = target.indexOf( b );
77         if ( ( i_a < 0 ) || ( i_b < i_a ) ) {
78             throw new IllegalArgumentException( "attempt to extract from [" + target + "] between [" + a + "] and ["
79                     + b + "]" );
80         }
81         return target.substring( i_a + a.length(), i_b ).trim();
82     }
83
84     /* (non-Javadoc)
85      * @see org.forester.ws.uniprot.SequenceDatabaseEntry#getAc()
86      */
87     @Override
88     public String getAccession() {
89         return _ac;
90     }
91
92     private void setAc( final String ac ) {
93         if ( _ac == null ) {
94             _ac = ac;
95         }
96     }
97
98     /* (non-Javadoc)
99      * @see org.forester.ws.uniprot.SequenceDatabaseEntry#getRecName()
100      */
101     @Override
102     public String getSequenceName() {
103         return _rec_name;
104     }
105
106     private void setRecName( final String rec_name ) {
107         if ( _rec_name == null ) {
108             _rec_name = rec_name;
109         }
110     }
111
112     /* (non-Javadoc)
113      * @see org.forester.ws.uniprot.SequenceDatabaseEntry#getOsScientificName()
114      */
115     @Override
116     public String getTaxonomyScientificName() {
117         return _os_scientific_name;
118     }
119
120     private void setOsScientificName( final String os_scientific_name ) {
121         if ( _os_scientific_name == null ) {
122             _os_scientific_name = os_scientific_name;
123         }
124     }
125
126     /* (non-Javadoc)
127      * @see org.forester.ws.uniprot.SequenceDatabaseEntry#getTaxId()
128      */
129     @Override
130     public String getTaxonomyIdentifier() {
131         return _tax_id;
132     }
133
134     private void setTaxId( final String tax_id ) {
135         if ( _tax_id == null ) {
136             _tax_id = tax_id;
137         }
138     }
139
140     /* (non-Javadoc)
141      * @see org.forester.ws.uniprot.SequenceDatabaseEntry#getSymbol()
142      */
143     @Override
144     public String getSequenceSymbol() {
145         return _symbol;
146     }
147
148     private void setSymbol( final String symbol ) {
149         if ( _symbol == null ) {
150             _symbol = symbol;
151         }
152     }
153 }