
org.campagnelab.dl.somatic.mappers.FeatureMapperV21 Maven / Gradle / Ivy
package org.campagnelab.dl.somatic.mappers;
import org.campagnelab.dl.framework.mappers.ConfigurableFeatureMapper;
import org.campagnelab.dl.somatic.mappers.functional.TraversalHelper;
import org.campagnelab.dl.varanalysis.protobuf.BaseInformationRecords;
import org.nd4j.linalg.api.ndarray.INDArray;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
/**
* Same as V20, with to information for each count, arranged as a sequence.
*/
public class FeatureMapperV21 extends NamingConcatFeatureMapper
implements ConfigurableFeatureMapper {
private NamingConcatFeatureMapper delegate;
private String recordTo(final int contextLength, BaseInformationRecords.BaseInformationOrBuilder record, int countIndex) {
return MappingFunctions.recordTo(contextLength,record, countIndex);
}
/**
* Configure the feature mapper for a specific set of sbi files. This method accesses the properties of the reader.
*
* @param sbiProperties properties from an sbi reader.
*/
public void configure(Properties sbiProperties) {
delegate = new NamingConcatFeatureMapper(
new SimpleFeatureCalculator(true),
new IndelFeatures(),
new GenomicContextMapper(sbiProperties),
// we reuse the genomic context mapper to map the to field for the first four genotypes (by decreasing count):
new GenomicPositionMapper(),
new GenomicContextMapper(1, record -> recordTo(1, record, 0)),
new GenomicContextMapper(1, record -> recordTo(1, record, 1)),
new GenomicContextMapper(1, record -> recordTo(1, record, 2)),
new GenomicContextMapper(1, record -> recordTo(1, record, 3)),
new ReadIndexFeaturesFix(),
new FractionDifferences4(),
new MagnitudeFeatures2(),
new DensityMapper("numVariationsInRead", 20, sbiProperties, baseInformationOrBuilder ->
TraversalHelper.forAllSampleCounts(baseInformationOrBuilder, BaseInformationRecords.CountInfo::getNumVariationsInReadsList)),
new DensityMapper("readMappingQuality.forward", 10, sbiProperties, baseInformationOrBuilder ->
TraversalHelper.forAllSampleCounts(baseInformationOrBuilder, BaseInformationRecords.CountInfo::getReadMappingQualityForwardStrandList)),
new DensityMapper("readMappingQuality.reverse", 10, sbiProperties, baseInformationOrBuilder ->
TraversalHelper.forAllSampleCounts(baseInformationOrBuilder, BaseInformationRecords.CountInfo::getReadMappingQualityReverseStrandList)),
new DensityMapper("baseQuality.forward", 10, sbiProperties, baseInformationOrBuilder ->
TraversalHelper.forAllSampleCounts(baseInformationOrBuilder, BaseInformationRecords.CountInfo::getQualityScoresForwardStrandList)),
new DensityMapper("baseQuality.reverse", 10, sbiProperties, baseInformationOrBuilder ->
TraversalHelper.forAllSampleCounts(baseInformationOrBuilder, BaseInformationRecords.CountInfo::getQualityScoresReverseStrandList))
);
}
@Override
public String getFeatureName(int i) {
return delegate.getFeatureName(i);
}
@Override
public int numberOfFeatures() {
return delegate.numberOfFeatures();
}
@Override
public void prepareToNormalize(BaseInformationRecords.BaseInformationOrBuilder record, int indexOfRecord) {
delegate.prepareToNormalize(record, indexOfRecord);
}
@Override
public void mapFeatures(BaseInformationRecords.BaseInformationOrBuilder record, INDArray inputs, int indexOfRecord) {
delegate.mapFeatures(record, inputs, indexOfRecord);
}
@Override
public float produceFeature(BaseInformationRecords.BaseInformationOrBuilder record, int featureIndex) {
return delegate.produceFeature(record, featureIndex);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy