Changeset 5757


Ignore:
Timestamp:
Nov 26, 2019, 9:25:39 AM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #1206: The MIPs aliquot importer should handle some values as special cases

Implemented the NormalTumor and Variant translations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/branches/4.24-stable/src/net/sf/basedb/reggie/plugins/AliquotImporter.java

    r5663 r5757  
    2323import net.sf.basedb.core.query.Restrictions;
    2424import net.sf.basedb.reggie.Reggie;
     25import net.sf.basedb.reggie.converter.ValueConverter;
    2526import net.sf.basedb.reggie.dao.Annotationtype;
    2627import net.sf.basedb.reggie.dao.BioplateType;
     
    190191    Mapper patientIdMapper = getOptionalMapper(ffp, "PatientID", fileAndLine);
    191192    Mapper provnummerMapper = getOptionalMapper(ffp, "Provnummer", fileAndLine);
     193   
     194    ValueConverter<String, String> normalTumorConverter = new TranslationConverter("TUMOR", "T", "NA", null);
     195    ValueConverter<String, String> variantConverter = new TranslationConverter("0", null);
    192196   
    193197    while (ffp.hasMoreData())
     
    211215      a.poolVolume = poolVolumeMapper.getString(data);
    212216      if (commentMapper != null) a.comment = commentMapper.getString(data);
    213       if (normalTumorMapper != null) a.normalTumor = normalTumorMapper.getString(data);
     217      if (normalTumorMapper != null) a.normalTumor = normalTumorConverter.convert(normalTumorMapper.getString(data));
    214218      if (formMapper != null) a.form = formMapper.getString(data);
    215       if (variantMapper != null) a.variant = variantMapper.getString(data);
     219      if (variantMapper != null) a.variant = variantConverter.convert(variantMapper.getString(data));
    216220      if (variantListMapper != null) a.variantList = variantListMapper.getString(data);
    217221      if (screeningMapper != null) a.screening = screeningMapper.getString(data);
     
    664668   
    665669  }
     670 
     671  /**
     672    A simple converter for string values. If a value is found in the
     673    translation map the translation is returned. Otherwise the original
     674    value is returned unmodified.
     675  */
     676  public static class TranslationConverter
     677    implements ValueConverter<String, String>
     678  {
     679
     680    private final Map<String, String> translation;
     681   
     682    /**
     683      Create a new translation. Key and values are provided
     684      as a single array with pair-wise entries. Eg.
     685      mapping[0] translates to mapping[1], mapping[2] translates to
     686      mapping[3], and so on.
     687    */
     688    public TranslationConverter(String... mapping)
     689    {
     690      this.translation = new HashMap<>();
     691      for (int i = 1; i < mapping.length; i+=2)
     692      {
     693        translation.put(mapping[i-1], mapping[i]);
     694      }
     695    }
     696   
     697    @Override
     698    public String convert(String key)
     699    {
     700      return translation.containsKey(key) ? translation.get(key) : key;
     701    }
     702  }
    666703}
Note: See TracChangeset for help on using the changeset viewer.