pattern match for up added....
[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     @Override
85     public String getAccession() {
86         return _ac;
87     }
88
89     private void setAc( final String ac ) {
90         if ( _ac == null ) {
91             _ac = ac;
92         }
93     }
94
95     @Override
96     public String getSequenceName() {
97         return _rec_name;
98     }
99
100     private void setRecName( final String rec_name ) {
101         if ( _rec_name == null ) {
102             _rec_name = rec_name;
103         }
104     }
105
106     @Override
107     public String getTaxonomyScientificName() {
108         return _os_scientific_name;
109     }
110
111     private void setOsScientificName( final String os_scientific_name ) {
112         if ( _os_scientific_name == null ) {
113             _os_scientific_name = os_scientific_name;
114         }
115     }
116
117     @Override
118     public String getTaxonomyIdentifier() {
119         return _tax_id;
120     }
121
122     private void setTaxId( final String tax_id ) {
123         if ( _tax_id == null ) {
124             _tax_id = tax_id;
125         }
126     }
127
128     @Override
129     public String getSequenceSymbol() {
130         return _symbol;
131     }
132
133     private void setSymbol( final String symbol ) {
134         if ( _symbol == null ) {
135             _symbol = symbol;
136         }
137     }
138 }