immuneML.encodings.baseline_encoding package¶
Submodules¶
immuneML.encodings.baseline_encoding.GeneFrequencyEncoder module¶
- class immuneML.encodings.baseline_encoding.GeneFrequencyEncoder.GeneFrequencyEncoder(genes: List[str], normalization_type: NormalizationType, scale_to_zero_mean: bool, scale_to_unit_variance: bool, name: str = None)[source]¶
Bases:
DatasetEncoderGeneFrequencyEncoder represents a repertoire by the frequency of V and/or J genes used.
Dataset type: - RepertoireDatasets
Specification arguments:
genes (list): List of genes to use for the encoding. Possible values are ‘V’, and ‘J’. At least one gene must be specified.
normalization_type (str): Type of normalization to apply to the gene frequencies. Possible values are ‘none’, ‘binary’, ‘relative_frequency’, ‘max’, ‘l2’. Defaults to ‘relative_frequency’.
scale_to_zero_mean (bool): Whether to scale the features to zero mean. Defaults to True.
scale_to_unit_variance (bool): Whether to scale the features to unit variance. Defaults to True.
YAML specification:
encodings: gene_frequency_encoding: GeneFrequency: genes: [V, J] normalization_type: relative_frequency scale_to_unit_variance: true scale_to_zero_mean: true
- property all_feature_names: List[str]¶
- 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:
Check parameters: immuneML should crash if wrong user parameters are specified. The ParameterValidator utility class may be used for parameter testing.
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.
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.
immuneML.encodings.baseline_encoding.MetadataEncoder module¶
- class immuneML.encodings.baseline_encoding.MetadataEncoder.MetadataEncoder(metadata_fields: list, name: str = None)[source]¶
Bases:
DatasetEncoderEncoder that uses metadata fields as features, such as HLA.
Dataset type: - RepertoireDatasets - SequenceDatasets - ReceptorDatasets
Specification arguments:
metadata_fields (list): List of metadata fields to use as features.
YAML specification:
encodings: metadata_encoding: Metadata: metadata_fields: [HLA, sex]
- 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:
Check parameters: immuneML should crash if wrong user parameters are specified. The ParameterValidator utility class may be used for parameter testing.
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.
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.
- immuneML.encodings.baseline_encoding.MetadataEncoder.flatten_comma_separated_mlb(df, column_name, mlb=None)[source]¶
Flatten comma-separated values using MultiLabelBinarizer.
Parameters:¶
- dfpandas DataFrame
Input dataframe
- column_namestr
Name of column containing comma-separated values
Returns:¶
pandas DataFrame with original columns + one-hot encoded columns