inprogress
[jalview.git] / forester / java / src / org / forester / ws / seqdb / 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: https://sites.google.com/site/cmzmasek/home/software/forester
25
26 package org.forester.ws.seqdb;
27
28 import java.util.List;
29
30 import org.forester.util.ForesterUtil;
31
32 public final class UniProtEntry implements SequenceDatabaseEntry {
33
34     private String _ac;
35     private String _name;
36     private String _os_scientific_name;
37     private String _tax_id;
38
39     private UniProtEntry() {
40     }
41
42     @Override
43     public Object clone() throws CloneNotSupportedException {
44         throw new CloneNotSupportedException();
45     }
46
47     public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
48         final UniProtEntry e = new UniProtEntry();
49         for( final String line : lines ) {
50             if ( line.startsWith( "AC" ) ) {
51                 e.setAc( DatabaseTools.extract( line, "AC", ";" ) );
52             }
53             else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceName() ) ) {
54                 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
55                     e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
56                 }
57                 else if ( ( line.indexOf( "SubName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
58                     e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
59                 }
60             }
61             else if ( line.startsWith( "OS" ) ) {
62                 if ( line.indexOf( "(" ) > 0 ) {
63                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "(" ) );
64                 }
65                 else {
66                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "." ) );
67                 }
68             }
69             else if ( line.startsWith( "OX" ) ) {
70                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
71                     e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
72                 }
73             }
74         }
75         return e;
76     }
77
78     @Override
79     public String getAccession() {
80         return _ac;
81     }
82
83     private void setAc( final String ac ) {
84         if ( _ac == null ) {
85             _ac = ac;
86         }
87     }
88
89     @Override
90     public String getSequenceName() {
91         return _name;
92     }
93
94     private void setSequenceName( final String name ) {
95         if ( _name == null ) {
96             _name = name;
97         }
98     }
99
100     @Override
101     public String getTaxonomyScientificName() {
102         return _os_scientific_name;
103     }
104
105     private void setOsScientificName( final String os_scientific_name ) {
106         if ( _os_scientific_name == null ) {
107             _os_scientific_name = os_scientific_name;
108         }
109     }
110
111     @Override
112     public String getTaxonomyIdentifier() {
113         return _tax_id;
114     }
115
116     private void setTaxId( final String tax_id ) {
117         if ( _tax_id == null ) {
118             _tax_id = tax_id;
119         }
120     }
121
122     @Override
123     public String getSequenceSymbol() {
124         return "";
125     }
126
127     @Override
128     public boolean isEmpty() {
129         return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
130                 && ForesterUtil.isEmpty( getTaxonomyScientificName() )
131                 && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil.isEmpty( getSequenceSymbol() ) );
132     }
133
134     @Override
135     public String getProvider() {
136         return "uniprot";
137     }
138 }