refactoring for DBMODList
[jalview.git] / src / jalview / datamodel / DBRefSource.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.datamodel;
22
23 /**
24  * BH 2018 SwingJS note: If additional final static Strings are added to this
25  * file, they should be added to public static final String[] allTypes.
26  * 
27  * Defines internal constants for unambiguous annotation of DbRefEntry source
28  * strings and describing the data retrieved from external database sources (see
29  * jalview.ws.DbSourcProxy) <br/>
30  * TODO: replace with ontology to allow recognition of particular attributes
31  * (e.g. protein coding, alignment (ortholog db, paralog db, domain db),
32  * genomic, transcriptomic, 3D structure providing (PDB, MODBASE, etc) ..).
33  * 
34  * 
35  * 
36  * @author JimP
37  * 
38  */
39 public class DBRefSource
40 {
41   
42   
43   
44   public static final String UNIPROT = "UNIPROT";
45   public static final String UP_NAME = "UNIPROT_NAME".toUpperCase();
46   /**
47    * Uniprot Knowledgebase/TrEMBL as served from EMBL protein products.
48    */
49   public static final String UNIPROTKB = "UniProtKB/TrEMBL".toUpperCase();
50
51   public static final String ENSEMBL        = "ENSEMBL";
52   public static final String ENSEMBLGENOMES = "ENSEMBLGENOMES";
53   
54   public static final String EMBL           = "EMBL";
55   public static final String EMBLCDS        = "EMBLCDS";
56   public static final String EMBLCDSProduct = "EMBLCDSProtein".toUpperCase();
57
58   public static final String PDB    = "PDB";
59   public static final String PFAM   = "PFAM";
60   public static final String RFAM   = "RFAM";
61   public static final String GENEDB = "GeneDB".toUpperCase();
62
63   public static final String PDB_CANONICAL_NAME = PDB;
64
65
66   public static final String[] allSources = new String[] {
67       UNIPROT, 
68       UP_NAME, UNIPROTKB, 
69       ENSEMBL, ENSEMBLGENOMES, 
70       EMBL, EMBLCDS, EMBLCDSProduct, 
71       PDB, PFAM, RFAM, GENEDB 
72       };  
73
74         public static final int UNIPROT_MASK          = 1<<0;
75         public static final int UP_NAME_MASK          = 1<<1;
76         public static final int UNIPROT_KB_MASK       = 1<<2;
77         public static final int ENSEMBL_MASK          = 1<<3;
78         public static final int ENSEMBL_GENOMES_MASK  = 1<<4;
79         public static final int EMBL_MASK             = 1<<5;
80         public static final int EMBL_CDS_MASK         = 1<<6;
81         public static final int EMBL_CDS_PRODUCT_MASK = 1<<7;
82         public static final int PDB_MASK              = 1<<8;
83         public static final int PFAM_MASK             = 1<<9;
84         public static final int RFAM_MASK             = 1<<10;
85         public static final int GENE_DB_MASK          = 1<<11;
86
87     public static final int MASK_COUNT = 12;
88           
89     public static final int ALL_MASKS = (1 << MASK_COUNT) - 1;
90
91         public static int getSourceKey(String name) {
92                   for (int i = 0; i < MASK_COUNT; i++) {
93                           if (name.equals(allSources[i]))
94                                 return 1<<i;
95                   }
96                   return 0;       
97           }
98
99         public static final int PRIMARY_MASK = UNIPROT_MASK | ENSEMBL_MASK;
100
101           /**
102           * List of databases whose sequences might have coding regions annotated
103           */
104          public static final String[] DNACODINGDBS = { 
105                      ENSEMBL, ENSEMBLGENOMES,
106                          EMBL, EMBLCDS, GENEDB
107              };
108         
109      public static final int DNA_CODING_MASK = 
110                  ENSEMBL_MASK | ENSEMBL_GENOMES_MASK
111           | EMBL_MASK | EMBL_CDS_MASK | GENE_DB_MASK;
112
113     
114      
115     public static final String[] CODINGDBS = { EMBLCDS, GENEDB, ENSEMBL };
116
117     public static final int CODING_MASK = EMBL_CDS_MASK | GENE_DB_MASK | ENSEMBL_MASK;
118   
119    
120   
121     public static final String[] PROTEINDBS = { 
122                 UNIPROT, UNIPROTKB,
123                 ENSEMBL, EMBLCDSProduct }; // Ensembl ENSP* entries are protein
124
125     public static final int PROTEIN_MASK = 
126                   UNIPROT_MASK | UNIPROT_KB_MASK 
127                 | ENSEMBL_MASK | EMBL_CDS_PRODUCT_MASK ;
128
129
130     // for SequenceAnnotationReport only
131     
132 //    public static final String[][] PRIMARY_SOURCES = new String[][] {
133 //        CODINGDBS, DNACODINGDBS, PROTEINDBS };
134 //        
135         public static final int PRIMARY_SOURCES_MASK = CODING_MASK | DNA_CODING_MASK | PROTEIN_MASK;
136         
137     public static boolean isPrimarySource(String source)
138     {
139         return ((PRIMARY_SOURCES_MASK & getSourceKey(source)) != 0);
140     }
141
142
143 //  public static String[] allSourcesFromReflection;
144 //
145 //  public static String[] allSources()
146 //
147 //  {
148 //    /**
149 //     * @j2sNative
150 //     * 
151 //     *            return C$.allTypes;
152 //     * 
153 //     */
154 //
155 //    {
156 //      if (allSourcesFromReflection == null)
157 //      {
158 //        List<String> src = new ArrayList<>();
159 //        for (Field f : DBRefSource.class.getFields())
160 //        {
161 //          if (String.class.equals(f.getType()))
162 //          {
163 //            try
164 //            {
165 //              src.add((String) f.get(null));
166 //            } catch (Exception x)
167 //            {
168 //              x.printStackTrace();
169 //            }
170 //          }
171 //        }
172 //        allSourcesFromReflection = src.toArray(new String[0]);
173 //      }
174 //      return allSourcesFromReflection;
175 //    }
176 //  }
177
178   public static boolean isPrimaryCandidate(String ucversion) {  
179     // tricky - this test really needs to search the sequence's set of dbrefs to
180     // see if there is a primary reference that derived this reference.
181     for (int i = allSources.length; --i >= 0;)
182     {
183       if (ucversion.startsWith(allSources[i])) // BH 2019.01.25 .toUpperCase() unnecessary here for allSources
184       {
185         // by convention, many secondary references inherit the primary
186         // reference's
187         // source string as a prefix for any version information from the
188         // secondary reference.
189         return false;
190       }
191     }
192     return true;
193 }
194
195
196
197   
198 }