c30dc4c50d4237211217ceb091a8ce1509f1f6a0
[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 _symbol;
37     private String _gene_name;
38     private String _os_scientific_name;
39     private String _tax_id;
40
41     private UniProtEntry() {
42     }
43
44     @Override
45     public Object clone() throws CloneNotSupportedException {
46         throw new CloneNotSupportedException();
47     }
48
49     public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
50         final UniProtEntry e = new UniProtEntry();
51         for( final String line : lines ) {
52             System.out.println( line );
53             if ( line.startsWith( "AC" ) ) {
54                 e.setAc( DatabaseTools.extract( line, "AC", ";" ) );
55             }
56             else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceName() ) ) {
57                 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
58                     e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
59                 }
60                 else if ( ( line.indexOf( "SubName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
61                     e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
62                 }
63             }
64             else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceSymbol() ) ) {
65                 if ( line.indexOf( "Short=" ) > 0 ) {
66                     e.setSequenceSymbol( DatabaseTools.extract( line, "Short=", ";" ) );
67                 }
68             }
69             else if ( line.startsWith( "GN" ) && ForesterUtil.isEmpty( e.getGeneName() ) ) {
70                 if ( line.indexOf( "Name=" ) > 0 ) {
71                     e.setGeneName( DatabaseTools.extract( line, "Name=", ";" ) );
72                 }
73             }
74             else if ( line.startsWith( "OS" ) ) {
75                 if ( line.indexOf( "(" ) > 0 ) {
76                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "(" ) );
77                 }
78                 else {
79                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "." ) );
80                 }
81             }
82             else if ( line.startsWith( "OX" ) ) {
83                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
84                     e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
85                 }
86             }
87         }
88         return e;
89     }
90
91     private void setSequenceSymbol( String symbol ) {
92         _symbol = symbol;
93     }
94
95     @Override
96     public String getAccession() {
97         return _ac;
98     }
99
100     private void setAc( final String ac ) {
101         if ( _ac == null ) {
102             _ac = ac;
103         }
104     }
105
106     @Override
107     public String getSequenceName() {
108         return _name;
109     }
110
111     private void setSequenceName( final String name ) {
112         if ( _name == null ) {
113             _name = name;
114         }
115     }
116
117     @Override
118     public String getTaxonomyScientificName() {
119         return _os_scientific_name;
120     }
121
122     private void setOsScientificName( final String os_scientific_name ) {
123         if ( _os_scientific_name == null ) {
124             _os_scientific_name = os_scientific_name;
125         }
126     }
127
128     @Override
129     public String getTaxonomyIdentifier() {
130         return _tax_id;
131     }
132
133     private void setTaxId( final String tax_id ) {
134         if ( _tax_id == null ) {
135             _tax_id = tax_id;
136         }
137     }
138
139     private void setGeneName( final String gene_name ) {
140         if ( _gene_name == null ) {
141             _gene_name = gene_name;
142         }
143     }
144
145     @Override
146     public String getSequenceSymbol() {
147         return _symbol;
148     }
149
150     @Override
151     public boolean isEmpty() {
152         return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
153                 && ForesterUtil.isEmpty( getTaxonomyScientificName() ) && ForesterUtil.isEmpty( getSequenceSymbol() )
154                 && ForesterUtil.isEmpty( getGeneName() ) && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil
155                 .isEmpty( getSequenceSymbol() ) );
156     }
157
158     @Override
159     public String getProvider() {
160         return "uniprot";
161     }
162
163     @Override
164     public String getGeneName() {
165         return _gene_name;
166     }
167 }