in progress
[jalview.git] / forester / java / src / org / forester / ws / uniprot / UniProtTaxonomyEntry.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 UniProtTaxonomyEntry {
31
32     private String _id;
33     private String _ac;
34     private String _rec_name;
35     private String _os_scientific_name;
36     private String _os_common_name;
37     private String _tax_id;
38
39     private UniProtTaxonomyEntry() {
40     }
41
42     public static UniProtTaxonomyEntry createInstanceFromPlainText( final List<String> lines ) {
43         final UniProtTaxonomyEntry e = new UniProtTaxonomyEntry();
44         for( final String line : lines ) {
45             if ( line.startsWith( "ID" ) ) {
46                 e.setId( line.split( "\\s+" )[ 1 ] );
47             }
48             else if ( line.startsWith( "AC" ) ) {
49                 e.setAc( extract( line, "AC", ";" ) );
50             }
51             else if ( line.startsWith( "DE" ) ) {
52                 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
53                     e.setRecName( extract( line, "Full=", ";" ) );
54                 }
55                 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
56                     e.setRecName( extract( line, "Full=", ";" ) );
57                 }
58             }
59             else if ( line.startsWith( "OS" ) ) {
60                 if ( line.indexOf( "(" ) > 0 ) {
61                     e.setOsScientificName( extract( line, "OS", "(" ) );
62                 }
63                 else {
64                     e.setOsScientificName( extract( line, "OS", "." ) );
65                 }
66             }
67             else if ( line.startsWith( "OX" ) ) {
68                 e.setTaxId( extract( line, "OX", ";" ) );
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() + 1, i_b - 1 ).trim();
82     }
83
84     public String getId() {
85         return _id;
86     }
87
88     private void setId( final String id ) {
89         _id = id;
90     }
91
92     public String getAc() {
93         return _ac;
94     }
95
96     private void setAc( final String ac ) {
97         _ac = ac;
98     }
99
100     public String getRecName() {
101         return _rec_name;
102     }
103
104     private void setRecName( final String rec_name ) {
105         _rec_name = rec_name;
106     }
107
108     public String getOsScientificName() {
109         return _os_scientific_name;
110     }
111
112     private void setOsScientificName( final String os_scientific_name ) {
113         _os_scientific_name = os_scientific_name;
114     }
115
116     public String getOsCommonName() {
117         return _os_common_name;
118     }
119
120     private void setOsCommonName( final String os_common_name ) {
121         _os_common_name = os_common_name;
122     }
123
124     public String getTaxId() {
125         return _tax_id;
126     }
127
128     private void setTaxId( final String tax_id ) {
129         _tax_id = tax_id;
130     }
131 }