222df5b0428651893f9b98f0f1023fb0b08aab47
[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( DatabaseTools.extract( line, "AC", ";" ) );
46             }
47             else if ( line.startsWith( "DE" ) ) {
48                 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
49                     e.setRecName( DatabaseTools.extract( line, "Full=", ";" ) );
50                 }
51             }
52             else if ( line.startsWith( "GN" ) ) {
53                 if ( ( line.indexOf( "Name=" ) > 0 ) ) {
54                     e.setSymbol( DatabaseTools.extract( line, "Name=", ";" ) );
55                 }
56             }
57             else if ( line.startsWith( "OS" ) ) {
58                 if ( line.indexOf( "(" ) > 0 ) {
59                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "(" ) );
60                 }
61                 else {
62                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "." ) );
63                 }
64             }
65             else if ( line.startsWith( "OX" ) ) {
66                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
67                     e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
68                 }
69             }
70         }
71         return e;
72     }
73
74     @Override
75     public String getAccession() {
76         return _ac;
77     }
78
79     private void setAc( final String ac ) {
80         if ( _ac == null ) {
81             _ac = ac;
82         }
83     }
84
85     @Override
86     public String getSequenceName() {
87         return _rec_name;
88     }
89
90     private void setRecName( final String rec_name ) {
91         if ( _rec_name == null ) {
92             _rec_name = rec_name;
93         }
94     }
95
96     @Override
97     public String getTaxonomyScientificName() {
98         return _os_scientific_name;
99     }
100
101     private void setOsScientificName( final String os_scientific_name ) {
102         if ( _os_scientific_name == null ) {
103             _os_scientific_name = os_scientific_name;
104         }
105     }
106
107     @Override
108     public String getTaxonomyIdentifier() {
109         return _tax_id;
110     }
111
112     private void setTaxId( final String tax_id ) {
113         if ( _tax_id == null ) {
114             _tax_id = tax_id;
115         }
116     }
117
118     @Override
119     public String getSequenceSymbol() {
120         return _symbol;
121     }
122
123     private void setSymbol( final String symbol ) {
124         if ( _symbol == null ) {
125             _symbol = symbol;
126         }
127     }
128 }