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 import java.util.regex.Matcher;
30 import java.util.regex.Pattern;
31
32 import org.forester.go.BasicGoTerm;
33 import org.forester.go.GoTerm;
34 import org.forester.util.ForesterUtil;
35
36 public final class UniProtEntry implements SequenceDatabaseEntry {
37
38     public final static Pattern GO_PATTERN = Pattern.compile( "GO;\\s+GO:(\\d+);\\s+([PF]):([^;]+);" );
39     private String              _ac;
40     private String              _name;
41     private String              _symbol;
42     private String              _gene_name;
43     private String              _os_scientific_name;
44     private String              _tax_id;
45
46     private UniProtEntry() {
47     }
48
49     @Override
50     public Object clone() throws CloneNotSupportedException {
51         throw new CloneNotSupportedException();
52     }
53
54     public static SequenceDatabaseEntry createInstanceFromPlainText( final List<String> lines ) {
55         final UniProtEntry e = new UniProtEntry();
56         for( final String line : lines ) {
57             //System.out.println( line );
58             if ( line.startsWith( "AC" ) ) {
59                 e.setAc( DatabaseTools.extract( line, "AC", ";" ) );
60             }
61             else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceName() ) ) {
62                 if ( ( line.indexOf( "RecName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
63                     e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
64                 }
65                 else if ( ( line.indexOf( "SubName:" ) > 0 ) && ( line.indexOf( "Full=" ) > 0 ) ) {
66                     e.setSequenceName( DatabaseTools.extract( line, "Full=", ";" ) );
67                 }
68             }
69             else if ( line.startsWith( "DE" ) && ForesterUtil.isEmpty( e.getSequenceSymbol() ) ) {
70                 if ( line.indexOf( "Short=" ) > 0 ) {
71                     e.setSequenceSymbol( DatabaseTools.extract( line, "Short=", ";" ) );
72                 }
73             }
74             else if ( line.startsWith( "GN" ) && ForesterUtil.isEmpty( e.getGeneName() ) ) {
75                 if ( line.indexOf( "Name=" ) > 0 ) {
76                     e.setGeneName( DatabaseTools.extract( line, "Name=", ";" ) );
77                 }
78             }
79             else if ( line.startsWith( "DR" ) ) {
80                 if ( line.indexOf( "GO;" ) > 0 ) {
81                     Matcher m = GO_PATTERN.matcher( line );
82                     if ( m.find() ) {
83                         String n = m.group( 1 );
84                         String ns_str = m.group( 2 );
85                         String desc = m.group( 3 );
86                         if ( ns_str.equals( "F" ) ) { 
87                         
88                         System.out.println( "GO:" + n + " " + desc + " " + ns );
89                         GoTerm go = new BasicGoTerm( n, desc, ns, false );
90                         //  e.setGeneName( DatabaseTools.extract( line, "Name=", ";" ) );
91                     }
92                 }
93             }
94             else if ( line.startsWith( "OS" ) ) {
95                 if ( line.indexOf( "(" ) > 0 ) {
96                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "(" ) );
97                 }
98                 else {
99                     e.setOsScientificName( DatabaseTools.extract( line, "OS", "." ) );
100                 }
101             }
102             else if ( line.startsWith( "OX" ) ) {
103                 if ( line.indexOf( "NCBI_TaxID=" ) > 0 ) {
104                     e.setTaxId( DatabaseTools.extract( line, "NCBI_TaxID=", ";" ) );
105                 }
106             }
107         }
108         return e;
109     }
110
111     private void setSequenceSymbol( String symbol ) {
112         _symbol = symbol;
113     }
114
115     @Override
116     public String getAccession() {
117         return _ac;
118     }
119
120     private void setAc( final String ac ) {
121         if ( _ac == null ) {
122             _ac = ac;
123         }
124     }
125
126     @Override
127     public String getSequenceName() {
128         return _name;
129     }
130
131     private void setSequenceName( final String name ) {
132         if ( _name == null ) {
133             _name = name;
134         }
135     }
136
137     @Override
138     public String getTaxonomyScientificName() {
139         return _os_scientific_name;
140     }
141
142     private void setOsScientificName( final String os_scientific_name ) {
143         if ( _os_scientific_name == null ) {
144             _os_scientific_name = os_scientific_name;
145         }
146     }
147
148     @Override
149     public String getTaxonomyIdentifier() {
150         return _tax_id;
151     }
152
153     private void setTaxId( final String tax_id ) {
154         if ( _tax_id == null ) {
155             _tax_id = tax_id;
156         }
157     }
158
159     private void setGeneName( final String gene_name ) {
160         if ( _gene_name == null ) {
161             _gene_name = gene_name;
162         }
163     }
164
165     @Override
166     public String getSequenceSymbol() {
167         return _symbol;
168     }
169
170     @Override
171     public boolean isEmpty() {
172         return ( ForesterUtil.isEmpty( getAccession() ) && ForesterUtil.isEmpty( getSequenceName() )
173                 && ForesterUtil.isEmpty( getTaxonomyScientificName() ) && ForesterUtil.isEmpty( getSequenceSymbol() )
174                 && ForesterUtil.isEmpty( getGeneName() ) && ForesterUtil.isEmpty( getTaxonomyIdentifier() ) && ForesterUtil
175                 .isEmpty( getSequenceSymbol() ) );
176     }
177
178     @Override
179     public String getProvider() {
180         return "uniprot";
181     }
182
183     @Override
184     public String getGeneName() {
185         return _gene_name;
186     }
187 }