2 // forester -- software libraries and applications
3 // for genomics and evolutionary biology research.
5 // Copyright (C) 2010 Christian M Zmasek
6 // Copyright (C) 2010 Sanford-Burnham Medical Research Institute
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.
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.
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
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org/forester
26 package org.forester.ws.uniprot;
28 import java.util.List;
30 public final class UniProtTaxonomyEntry {
34 private String _rec_name;
35 private String _os_scientific_name;
36 private String _os_common_name;
37 private String _tax_id;
39 private UniProtTaxonomyEntry() {
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 ] );
48 else if ( line.startsWith( "AC" ) ) {
49 e.setAc( extract( line, "AC", ";" ) );
51 else if ( line.startsWith( "DE" ) ) {
52 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
53 e.setRecName( extract( line, "Full=", ";" ) );
55 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
56 e.setRecName( extract( line, "Full=", ";" ) );
59 else if ( line.startsWith( "OS" ) ) {
60 if ( line.indexOf( "(" ) > 0 ) {
61 e.setOsScientificName( extract( line, "OS", "(" ) );
64 e.setOsScientificName( extract( line, "OS", "." ) );
67 else if ( line.startsWith( "OX" ) ) {
68 e.setTaxId( extract( line, "OX", ";" ) );
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 ["
81 return target.substring( i_a + a.length() + 1, i_b - 1 ).trim();
84 public String getId() {
88 private void setId( final String id ) {
92 public String getAc() {
96 private void setAc( final String ac ) {
100 public String getRecName() {
104 private void setRecName( final String rec_name ) {
105 _rec_name = rec_name;
108 public String getOsScientificName() {
109 return _os_scientific_name;
112 private void setOsScientificName( final String os_scientific_name ) {
113 _os_scientific_name = os_scientific_name;
116 public String getOsCommonName() {
117 return _os_common_name;
120 private void setOsCommonName( final String os_common_name ) {
121 _os_common_name = os_common_name;
124 public String getTaxId() {
128 private void setTaxId( final String tax_id ) {