immuneML.encodings.composite_encoding package

Submodules

immuneML.encodings.composite_encoding.CompositeEncoder module

class immuneML.encodings.composite_encoding.CompositeEncoder.CompositeEncoder(encoders: List[DatasetEncoder], name: str = None)[source]

Bases: DatasetEncoder

This encoder allows to combine multiple different encodings together, for example, KmerFrequency encoder with VGeneEncoder. The parameters for the different encoders are passed as a list of dictionaries, where each dictionary contains the parameters for one encoder. The different encoders are applied sequentially and their results concatenated together.

Dataset type: - SequenceDatasets - ReceptorDatasets - RepertoireDatasets

Note

To combine multiple encodings (e.g., GeneFrequency and KmerFrequency), keep in mind how the ML method will use the encoded data downstream. Currently, the recommended way to use CompositeEncoder is with LogRegressionCustomPenalty, where you can specify which features should not be penalized.

Specification arguments:

  • encoders (list): A list of dictionaries, where each dictionary contains the parameters for one encoder.

YAML specification:

encodings:
    my_composite_encoding:
        Composite:
            encoders:
                - KmerFrequency:
                    k: 3
                - GeneFrequency:
                    genes: [V]
                    normalization_type: relative_frequency
                    scale_to_unit_variance: true
                    scale_to_zero_mean: true
static build_object(dataset: Dataset, **params)[source]

Creates an instance of the relevant subclass of the DatasetEncoder class using the given parameters. This method will be called during parsing time (early in the immuneML run), such that parameters and dataset type can be tested here.

The build_object method should do the following:

  1. Check parameters: immuneML should crash if wrong user parameters are specified. The ParameterValidator utility class may be used for parameter testing.

  2. Check the dataset type: immuneML should crash if the wrong dataset type is specified for this encoder. For example, DeepRCEncoder should only work for RepertoireDatasets and crash if the dataset is of another type.

  3. Create an instance of the correct Encoder class, using the given parameters. Return this object. Some encoders have different subclasses depending on the dataset type. Make sure to return an instance of the correct subclass. For instance: KmerFrequencyEncoder has different subclasses for each dataset type. When the dataset is a Repertoire dataset, KmerFreqRepertoireEncoder should be returned.

Parameters:
  • dataset – Dataset object of the same class as the dataset to be encoded later; in case there are multiple dataset types supported by the encoder, the dataset should be of one of these types and the correct subclass of the encoder should be returned

  • **params – keyword arguments that will be provided by users in the specification (if immuneML is used as a command line tool) or in the dictionary when calling the method from the code, and which should be used to create the Encoder object

Returns:

the object of the appropriate Encoder class

encode(dataset, params: EncoderParams) Dataset[source]

This is the main encoding method of the Encoder. It takes in a given dataset, computes an EncodedData object, and returns a copy of the dataset with the attached EncodedData object.

Parameters:
  • dataset – A dataset object (Sequence, Receptor or RepertoireDataset)

  • params – An EncoderParams object containing few utility parameters which may be used during encoding (e.g., number of parallel processes to use).

Returns:

A copy of the original dataset, with an EncodedData object added to the dataset.encoded_data field.

Module contents