001/* 002 * Copyright 2018 Leibniz-Institut für Analytische Wissenschaften – ISAS – e.V.. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package uk.ac.ebi.pride.jmztab2.model; 017 018/** 019 * Every line in an mzTab file MUST start with a three letter code identifying the type of line delimited by 020 * a Tab character. The three letter codes are as follows : 021 * - MTD for metadata 022 * - PRH for the protein table header line (the column labels) 023 * - PRT for rows of the protein table 024 * - PEH for the peptide table header line (the column labels) 025 * - PEP for rows of the peptide table 026 * - PSH for the PSM table header (the column labels) 027 * - PSM for rows of the PSM table 028 * - SMH for small molecule table header line (the column labels) 029 * - SML for rows of the small molecule table 030 * - COM for comment lines 031 * 032 * @author qingwei 033 * @author jgriss 034 * @author nilshoffmann 035 * @since 31/01/13 036 * 037 */ 038public enum Section { 039 Comment ("COM", "comment", 0), 040 Metadata ("MTD", "metadata", 1), 041 Protein_Header ("PRH", "protein_header", 2), 042 Protein ("PRT", "protein", 3), 043 Peptide_Header ("PEH", "peptide_header", 4), 044 Peptide ("PEP", "peptide", 5), 045 PSM_Header ("PSH", "psm_header", 6), 046 PSM ("PSM", "psm", 7), 047 Small_Molecule_Header ("SMH", "small_molecule_header", 8), 048 Small_Molecule ("SML", "small_molecule", 9), 049 Small_Molecule_Feature_Header ("SFH", "small_molecule_feature_header", 10), 050 Small_Molecule_Feature ("SMF", "small_molecule_feature", 11), 051 Small_Molecule_Evidence_Header ("SEH", "small_molecule_evidence_header", 12), 052 Small_Molecule_Evidence ("SME", "small_molecule_evidence", 13); 053 054 055 private final String prefix; 056 private final String name; 057 private final int level; 058 059 Section(String prefix, String name, int level) { 060 this.prefix = prefix; 061 this.name = name; 062 this.level = level; 063 } 064 065 /** 066 * <p>Getter for the field <code>prefix</code>.</p> 067 * 068 * @return a {@link java.lang.String} object. 069 */ 070 public String getPrefix() { 071 return prefix; 072 } 073 074 /** 075 * <p>Getter for the field <code>name</code>.</p> 076 * 077 * @return a {@link java.lang.String} object. 078 */ 079 public String getName() { 080 return name; 081 } 082 083 /** 084 * <p>Getter for the field <code>level</code>.</p> 085 * 086 * @return a int. 087 */ 088 public int getLevel() { 089 return level; 090 } 091 092 /** 093 * <p>findSection.</p> 094 * 095 * @param level a int. 096 * @return a {@link uk.ac.ebi.pride.jmztab2.model.Section} object. 097 */ 098 public static Section findSection(int level) { 099 Section section; 100 switch (level) { 101 case 0: 102 section = Comment; 103 break; 104 case 1: 105 section = Metadata; 106 break; 107 case 2: 108 section = Protein_Header; 109 break; 110 case 3: 111 section = Protein; 112 break; 113 case 4: 114 section = Peptide_Header; 115 break; 116 case 5: 117 section = Peptide; 118 break; 119 case 6: 120 section = PSM_Header; 121 break; 122 case 7: 123 section = PSM; 124 break; 125 case 8: 126 section = Small_Molecule_Header; 127 break; 128 case 9: 129 section = Small_Molecule; 130 break; 131 case 10: 132 section = Small_Molecule_Feature_Header; 133 break; 134 case 11: 135 section = Small_Molecule_Feature; 136 break; 137 case 12: 138 section = Small_Molecule_Evidence_Header; 139 break; 140 case 13: 141 section = Small_Molecule_Evidence; 142 break; 143 default: 144 section = null; 145 } 146 147 return section; 148 } 149 150 /** 151 * Judge the section is comment section or not. 152 * 153 * @return a boolean. 154 */ 155 public boolean isComment() { 156 return this == Comment; 157 } 158 159 /** 160 * Judge the section is metadata section or not. 161 * 162 * @return a boolean. 163 */ 164 public boolean isMetadata() { 165 return this == Metadata; 166 } 167 168 /** 169 * Judge the section is protein_header, peptide_header, psm_header, small_molecule_header, small_molecule_feature_header or small_molecule_evidence_header section. 170 * 171 * @return a boolean. 172 */ 173 public boolean isHeader() { 174 return this == Protein_Header || this == Peptide_Header || this == PSM_Header || this == Small_Molecule_Header || this == Small_Molecule_Feature_Header || this == Small_Molecule_Evidence_Header; 175 } 176 177 /** 178 * Judge the section is protein, peptide, psm, small_molecule, small_molecule_feature or small_molecule_evidence section. 179 * 180 * @return a boolean. 181 */ 182 public boolean isData() { 183 return this == Protein || this == Peptide || this == PSM || this == Small_Molecule || this == Small_Molecule_Feature || this == Small_Molecule_Evidence; 184 } 185 186 /** 187 * Translate the section to corresponding header section. If can not mapping, return null. 188 * Metadata, Comment --> null 189 * Protein, Protein_Header --> ProteinHeader 190 * Peptide, Peptide_Header --> PeptideHeader 191 * PSM, PSM_Header --> PSMHeader 192 * SmallMolecule, SmallMolecule_Header --> SmallMoleculeHeader 193 * SmallMoleculeFeature, SmallMoleculeFeature_Header --> SmallMoleculeFeatureHeader 194 * SmallMoleculeEvidence, SmallMoleculeEvidence_Header --> SmallMoleculeEvidenceHeader 195 * 196 * @see #toDataSection(Section) 197 * @param section a {@link uk.ac.ebi.pride.jmztab2.model.Section} object. 198 * @return a {@link uk.ac.ebi.pride.jmztab2.model.Section} object. 199 */ 200 public static Section toHeaderSection(Section section) { 201 Section header; 202 switch (section) { 203 case Peptide: 204 case Peptide_Header: 205 header = Section.Peptide_Header; 206 break; 207 case Protein: 208 case Protein_Header: 209 header = Section.Protein_Header; 210 break; 211 case PSM: 212 case PSM_Header: 213 header = Section.PSM_Header; 214 break; 215 case Small_Molecule: 216 case Small_Molecule_Header: 217 header = Section.Small_Molecule_Header; 218 break; 219 case Small_Molecule_Feature: 220 case Small_Molecule_Feature_Header: 221 header = Section.Small_Molecule_Feature_Header; 222 break; 223 case Small_Molecule_Evidence: 224 case Small_Molecule_Evidence_Header: 225 header = Section.Small_Molecule_Evidence_Header; 226 break; 227 default: 228 header = null; 229 } 230 231 return header; 232 } 233 234 /** 235 * Translate the section to corresponding data section. If can not mapping, return null. 236 * Metadata, Comment --> null 237 * Protein, Protein_Header --> Protein 238 * Peptide, Peptide_Header --> Peptide 239 * PSM, PSM_Header --> PSMHeader 240 * SmallMolecule, SmallMolecule_Header --> SmallMolecule 241 * SmallMoleculeFeature, SmallMoleculeFeature_Header --> SmallMoleculeFeature 242 * SmallMoleculeEvidence, SmallMoleculeEvidence_Header --> SmallMoleculeEvidence 243 * 244 * @see #toHeaderSection(Section) 245 * @param section a {@link uk.ac.ebi.pride.jmztab2.model.Section} object. 246 * @return a {@link uk.ac.ebi.pride.jmztab2.model.Section} object. 247 */ 248 public static Section toDataSection(Section section) { 249 Section data; 250 switch (section) { 251 case Peptide: 252 case Peptide_Header: 253 data = Section.Peptide; 254 break; 255 case Protein: 256 case Protein_Header: 257 data = Section.Protein; 258 break; 259 case PSM: 260 case PSM_Header: 261 data = Section.PSM; 262 break; 263 case Small_Molecule: 264 case Small_Molecule_Header: 265 data = Section.Small_Molecule; 266 break; 267 case Small_Molecule_Feature: 268 case Small_Molecule_Feature_Header: 269 data = Section.Small_Molecule_Feature; 270 break; 271 case Small_Molecule_Evidence: 272 case Small_Molecule_Evidence_Header: 273 data = Section.Small_Molecule_Evidence; 274 break; 275 default: 276 data = null; 277 } 278 279 return data; 280 } 281 282 /** 283 * Query section based on its name or prefix with case-insensitive. For example: 284 * findSection("protein") == findSection("PRT"); 285 * Both of them to locate the {@link uk.ac.ebi.pride.jmztab2.model.Section#Protein} 286 * 287 * @param key if empty, return null. 288 * @return a {@link uk.ac.ebi.pride.jmztab2.model.Section} object. 289 */ 290 public static Section findSection(String key) { 291 if (MZTabStringUtils.isEmpty(key)) { 292 return null; 293 } 294 295 key = key.trim(); 296 297 if (key.equalsIgnoreCase(Comment.getName()) || key.equalsIgnoreCase(Comment.getPrefix())) { 298 return Comment; 299 } else if (key.equalsIgnoreCase(Metadata.getName()) || key.equalsIgnoreCase(Metadata.getPrefix())) { 300 return Metadata; 301 } else if (key.equalsIgnoreCase(Peptide_Header.getName()) || key.equalsIgnoreCase(Peptide_Header.getPrefix())) { 302 return Peptide_Header; 303 } else if (key.equalsIgnoreCase(Peptide.getName()) || key.equalsIgnoreCase(Peptide.getPrefix())) { 304 return Peptide; 305 } else if (key.equalsIgnoreCase(Protein_Header.getName()) || key.equalsIgnoreCase(Protein_Header.getPrefix())) { 306 return Protein_Header; 307 } else if (key.equalsIgnoreCase(Protein.getName()) || key.equalsIgnoreCase(Protein.getPrefix())) { 308 return Protein; 309 } else if (key.equalsIgnoreCase(PSM_Header.getName()) || key.equalsIgnoreCase(PSM_Header.getPrefix())) { 310 return PSM_Header; 311 } else if (key.equalsIgnoreCase(PSM.getName()) || key.equalsIgnoreCase(PSM.getPrefix())) { 312 return PSM; 313 } else if (key.equalsIgnoreCase(Small_Molecule_Header.getName()) || key.equalsIgnoreCase(Small_Molecule_Header.getPrefix())) { 314 return Small_Molecule_Header; 315 } else if (key.equalsIgnoreCase(Small_Molecule.getName()) || key.equalsIgnoreCase(Small_Molecule.getPrefix())) { 316 return Small_Molecule; 317 } else if (key.equalsIgnoreCase(Small_Molecule_Feature_Header.getName()) || key.equalsIgnoreCase(Small_Molecule_Feature_Header.getPrefix())) { 318 return Small_Molecule_Feature_Header; 319 } else if (key.equalsIgnoreCase(Small_Molecule_Feature.getName()) || key.equalsIgnoreCase(Small_Molecule_Feature.getPrefix())) { 320 return Small_Molecule_Feature; 321 } else if (key.equalsIgnoreCase(Small_Molecule_Evidence_Header.getName()) || key.equalsIgnoreCase(Small_Molecule_Evidence_Header.getPrefix())) { 322 return Small_Molecule_Evidence_Header; 323 } else if (key.equalsIgnoreCase(Small_Molecule_Evidence.getName()) || key.equalsIgnoreCase(Small_Molecule_Evidence.getPrefix())) { 324 return Small_Molecule_Evidence; 325 } else { 326 return null; 327 } 328 } 329}