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
018import java.util.Optional;
019
020/**
021 * Define a property in metadata, which depend on the {@link uk.ac.ebi.pride.jmztab2.model.MetadataElement}.
022 *
023 * @author qingwei
024 * @author nilshoffmann
025 * @since 23/05/13
026 * 
027 */
028public enum MetadataProperty {
029    MZTAB_VERSION                         (MetadataElement.MZTAB,                               "version"),
030    MZTAB_ID                              (MetadataElement.MZTAB,                               "ID"),
031
032    INSTRUMENT_NAME                       (MetadataElement.INSTRUMENT,                          "name"),
033    INSTRUMENT_SOURCE                     (MetadataElement.INSTRUMENT,                          "source"),
034    INSTRUMENT_ANALYZER                   (MetadataElement.INSTRUMENT,                          "analyzer"),
035    INSTRUMENT_DETECTOR                   (MetadataElement.INSTRUMENT,                          "detector"),
036
037    SOFTWARE_SETTING                      (MetadataElement.SOFTWARE,                            "setting"),
038
039    CONTACT_NAME                          (MetadataElement.CONTACT,                             "name"),
040    CONTACT_AFFILIATION                   (MetadataElement.CONTACT,                             "affiliation"),
041    CONTACT_EMAIL                         (MetadataElement.CONTACT,                             "email"),
042
043    SMALL_MOLECULE_QUANTIFICATION_UNIT    (MetadataElement.SMALL_MOLECULE,                      "quantification_unit"),
044    SMALL_MOLECULE_IDENTIFICATION_RELIABILITY(MetadataElement.SMALL_MOLECULE,                   "identification_reliability"),
045    SMALL_MOLECULE_FEATURE_QUANTIFICATION_UNIT(MetadataElement.SMALL_MOLECULE_FEATURE,          "quantification_unit"),
046
047    MS_RUN_FORMAT                         (MetadataElement.MS_RUN,                              "format"),
048    MS_RUN_LOCATION                       (MetadataElement.MS_RUN,                              "location"),
049    MS_RUN_INSTRUMENT_REF                 (MetadataElement.MS_RUN,                              "instrument_ref"),
050    MS_RUN_ID_FORMAT                      (MetadataElement.MS_RUN,                              "id_format"),
051    MS_RUN_FRAGMENTATION_METHOD           (MetadataElement.MS_RUN,                              "fragmentation_method"),
052    MS_RUN_HASH                           (MetadataElement.MS_RUN,                              "hash"),
053    MS_RUN_HASH_METHOD                    (MetadataElement.MS_RUN,                              "hash_method"),
054    MS_RUN_SCAN_POLARITY                  (MetadataElement.MS_RUN,                              "scan_polarity"),
055
056    SAMPLE_SPECIES                        (MetadataElement.SAMPLE,                              "species"),
057    SAMPLE_TISSUE                         (MetadataElement.SAMPLE,                              "tissue"),
058    SAMPLE_CELL_TYPE                      (MetadataElement.SAMPLE,                              "cell_type"),
059    SAMPLE_DISEASE                        (MetadataElement.SAMPLE,                              "disease"),
060    SAMPLE_DESCRIPTION                    (MetadataElement.SAMPLE,                              "description"),
061    SAMPLE_CUSTOM                         (MetadataElement.SAMPLE,                              "custom"),
062
063    ASSAY_SAMPLE_REF                      (MetadataElement.ASSAY,                               "sample_ref"),
064    ASSAY_MS_RUN_REF                      (MetadataElement.ASSAY,                               "ms_run_ref"),
065    ASSAY_CUSTOM                          (MetadataElement.ASSAY,                               "custom"),
066    ASSAY_EXTERNAL_URI                    (MetadataElement.ASSAY,                               "external_uri"),
067
068    STUDY_VARIABLE_ASSAY_REFS             (MetadataElement.STUDY_VARIABLE,                      "assay_refs"),
069    STUDY_VARIABLE_DESCRIPTION            (MetadataElement.STUDY_VARIABLE,                      "description"),
070    STUDY_VARIABLE_AVERAGE_FUNCTION       (MetadataElement.STUDY_VARIABLE,                      "average_function"),
071    STUDY_VARIABLE_VARIATION_FUNCTION     (MetadataElement.STUDY_VARIABLE,                      "variation_function"),
072    STUDY_VARIABLE_FACTORS                (MetadataElement.STUDY_VARIABLE,                      "factors"),
073
074    CV_LABEL                              (MetadataElement.CV,                                  "label"),
075    CV_FULL_NAME                          (MetadataElement.CV,                                  "full_name"),
076    CV_VERSION                            (MetadataElement.CV,                                  "version"),
077    CV_URI                                (MetadataElement.CV,                                  "uri"),
078    
079    DATABASE_PREFIX                       (MetadataElement.DATABASE,                             "prefix"),
080    DATABASE_VERSION                      (MetadataElement.DATABASE,                             "version"),
081    DATABASE_URI                          (MetadataElement.DATABASE,                             "uri");
082    
083    private String name;
084    private MetadataElement element;
085
086    /**
087     * Define a property depend on {@link MetadataElement}
088     * For example: assay[1-n]-sample_ref, assay[1-n] is {@link MetadataElement#ASSAY},
089     * sample_ref is {@link MetadataProperty#ASSAY_SAMPLE_REF}
090     */
091    MetadataProperty(MetadataElement element, String name) {
092        this.element = element;
093        this.name = name;
094    }
095
096    /**
097     * <p>Getter for the field <code>element</code>.</p>
098     *
099     * @return dependent {@link uk.ac.ebi.pride.jmztab2.model.MetadataElement}
100     */
101    public MetadataElement getElement() {
102        return element;
103    }
104
105    /**
106     * <p>Getter for the field <code>name</code>.</p>
107     *
108     * @return property name
109     */
110    public String getName() {
111        return name;
112    }
113
114    /** {@inheritDoc} */
115    @Override
116    public String toString() {
117        return name;
118    }
119
120    /**
121     * Find property by {@link uk.ac.ebi.pride.jmztab2.model.MetadataElement} and property name with case-insensitive. If not find, return null.
122     *
123     * @param element a {@link uk.ac.ebi.pride.jmztab2.model.MetadataElement} object.
124     * @param propertyName a {@link java.lang.String} object.
125     * @return an optional {@link uk.ac.ebi.pride.jmztab2.model.MetadataProperty} object.
126     */
127    public static Optional<MetadataProperty> findProperty(MetadataElement element, String propertyName) {
128        if (element == null || propertyName == null) {
129            return Optional.empty();
130        }
131
132        MetadataProperty property;
133        try {
134            property = MetadataProperty.valueOf((element.getName() + "_" + propertyName).toUpperCase());
135        } catch (IllegalArgumentException e) {
136            property = null;
137        }
138
139        return Optional.ofNullable(property);
140    }
141}