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 de.isas.mztab2.model.IndexedElement; 019import de.isas.mztab2.model.SmallMoleculeFeature; 020import static de.isas.mztab2.model.SmallMoleculeFeature.Properties.*; 021import de.isas.mztab2.model.StringList; 022import java.util.Arrays; 023import java.util.List; 024import java.util.stream.Collectors; 025 026/** 027 * Define the stable columns which have stable order in the small molecule 028 * feature header line. 029 * 030 * To create optional column mappings, see 031 * {@link uk.ac.ebi.pride.jmztab2.model.OptColumnMappingBuilder}. 032 * 033 * @author nilshoffmann 034 * @since 11/09/17 035 * 036 */ 037public class SmallMoleculeFeatureColumn implements ISmallMoleculeFeatureColumn { 038 039 private final IMZTabColumn column; 040 041 SmallMoleculeFeatureColumn(String name, Class dataType, boolean optional, 042 String order) { 043 this.column = new MZTabColumn(name, dataType, optional, order); 044 } 045 046 SmallMoleculeFeatureColumn(String name, Class dataType, boolean optional, 047 String order, Integer id) { 048 this.column = new MZTabColumn(name, dataType, optional, order, id); 049 } 050 051 /** 052 * Stable {@link SmallMoleculeFeatureColumn} definition templates. 053 */ 054 public static enum Stable { 055 SMF_ID(smfId.toUpper(), Integer.class, false, "01"), 056 SME_ID_REFS(smeIdRefs.toUpper(), StringList.class, true, "02"), 057 SME_ID_REF_AMBIGUITY_CODE("SME_ID_REF_ambiguity_code", Integer.class, 058 true, "03"), 059 ADDUCT_ION( 060 adductIon, String.class, true, "04"), 061 ISOTOPOMER(isotopomer, String.class, true, "05"), 062 EXP_MASS_TO_CHARGE( 063 expMassToCharge, Double.class, false, "06"), 064 CHARGE(charge, Integer.class, false, "07"), 065 RETENTION_TIME_IN_SECONDS(retentionTimeInSeconds, Double.class, true, 066 "08"), 067 RETENTION_TIME_IN_SECONDS_START(retentionTimeInSecondsStart, 068 Double.class, true, "09"), 069 RETENTION_TIME_IN_SECONDS_END(retentionTimeInSecondsEnd, Double.class, 070 true, "10"); 071 072 private final ISmallMoleculeFeatureColumn column; 073 074 private Stable(SmallMoleculeFeature.Properties property, 075 Class columnType, boolean optional, 076 String order) { 077 this.column = new SmallMoleculeFeatureColumn(property. 078 getPropertyName(), columnType, optional, 079 order); 080 } 081 082 private Stable(String name, Class columnType, boolean optional, 083 String order) { 084 this.column = new SmallMoleculeFeatureColumn(name, columnType, 085 optional, 086 order); 087 } 088 089 private Stable(String name, Class columnType, boolean optional, 090 String order, Integer id) { 091 this.column = new SmallMoleculeFeatureColumn(name, columnType, 092 optional, 093 order, id); 094 } 095 096 /** 097 * Returns a stable column instance template. 098 * 099 * @param name the column name (lower case). 100 * @return the stable column instance template. 101 * @throws IllegalArgumentException for unknown column names. 102 */ 103 public static Stable forName(String name) throws IllegalArgumentException { 104 Stable s = Arrays.stream(Stable.values()). 105 filter((v) -> 106 v.column. 107 getName(). 108 equals(name)). 109 findFirst(). 110 orElseThrow(() -> 111 new IllegalArgumentException("Unknown key:" + name)); 112 return s; 113 } 114 115 /** 116 * Returns a new {@link ISmallMoleculeFeatureColumn} instance for the 117 * given stable column template. 118 * 119 * @param s the small molecule feature stable column template. 120 * @return a new small molecule feature column instance 121 * {@link SmallMoleculeFeatureColumn}. 122 */ 123 public static ISmallMoleculeFeatureColumn columnFor( 124 SmallMoleculeFeatureColumn.Stable s) { 125 return new SmallMoleculeFeatureColumn(s.column.getName(), s.column. 126 getDataType(), s.column.isOptional(), s.column.getOrder()); 127 } 128 129 /** 130 * Returns a new {@link ISmallMoleculeFeatureColumn} instance for the 131 * given stable column name. 132 * 133 * @param name the small molecule feature stable column template name 134 * (lower case). 135 * @return a new small molecule feature column instance 136 * {@link SmallMoleculeFeatureColumn}. 137 * @throws IllegalArgumentException for unknown column names. 138 */ 139 public static ISmallMoleculeFeatureColumn columnFor(String name) throws IllegalArgumentException { 140 return columnFor(forName(name)); 141 } 142 143 /** 144 * Returns all stable {@link ISmallMoleculeFeatureColumn} templates. 145 * 146 * @return the stable small molecule feature columns templates. 147 */ 148 public static List<ISmallMoleculeFeatureColumn> columns() { 149 return Arrays.stream(Stable.values()). 150 map((s) -> 151 { 152 return new SmallMoleculeFeatureColumn(s.column.getName(), 153 s.column.getDataType(), s.column.isOptional(), s.column. 154 getOrder()); 155 }). 156 collect(Collectors.toList()); 157 } 158 159 }; 160 161 /** 162 * {@inheritDoc} 163 */ 164 @Override 165 public Class<?> getDataType() { 166 return this.column.getDataType(); 167 } 168 169 /** 170 * {@inheritDoc} 171 */ 172 @Override 173 public IndexedElement getElement() { 174 return this.column.getElement(); 175 } 176 177 /** 178 * {@inheritDoc} 179 */ 180 @Override 181 public String getHeader() { 182 return this.column.getHeader(); 183 } 184 185 /** 186 * {@inheritDoc} 187 */ 188 @Override 189 public String getLogicPosition() { 190 return this.column.getLogicPosition(); 191 } 192 193 /** 194 * {@inheritDoc} 195 */ 196 @Override 197 public String getName() { 198 return this.column.getName(); 199 } 200 201 /** 202 * {@inheritDoc} 203 */ 204 @Override 205 public String getOrder() { 206 return this.column.getOrder(); 207 } 208 209 /** 210 * {@inheritDoc} 211 */ 212 @Override 213 public boolean isOptional() { 214 return this.column.isOptional(); 215 } 216 217 /** 218 * {@inheritDoc} 219 */ 220 @Override 221 public void setHeader(String header) { 222 this.column.setHeader(header); 223 } 224 225 /** 226 * {@inheritDoc} 227 */ 228 @Override 229 public void setLogicPosition(String logicPosition) { 230 this.column.setLogicPosition(logicPosition); 231 } 232 233 /** 234 * {@inheritDoc} 235 */ 236 @Override 237 public void setOrder(String order) { 238 this.column.setOrder(order); 239 } 240 241 /** 242 * {@inheritDoc} 243 */ 244 @Override 245 public void setElement(IndexedElement element) { 246 this.column.setElement(element); 247 } 248}