immuneML.encodings.kmer_frequency package

Submodules

immuneML.encodings.kmer_frequency.KmerFreqReceptorEncoder module

class immuneML.encodings.kmer_frequency.KmerFreqReceptorEncoder.KmerFreqReceptorEncoder(normalization_type: immuneML.analysis.data_manipulation.NormalizationType.NormalizationType, reads: immuneML.util.ReadsType.ReadsType, sequence_encoding: immuneML.encodings.kmer_frequency.sequence_encoding.SequenceEncodingType.SequenceEncodingType, k: int = 0, k_left: int = 0, k_right: int = 0, min_gap: int = 0, max_gap: int = 0, metadata_fields_to_include: Optional[list] = None, name: Optional[str] = None, scale_to_unit_variance: bool = False, scale_to_zero_mean: bool = False, sequence_type: Optional[immuneML.environment.SequenceType.SequenceType] = None)[source]

Bases: immuneML.encodings.kmer_frequency.KmerFrequencyEncoder.KmerFrequencyEncoder

immuneML.encodings.kmer_frequency.KmerFreqRepertoireEncoder module

class immuneML.encodings.kmer_frequency.KmerFreqRepertoireEncoder.KmerFreqRepertoireEncoder(normalization_type: immuneML.analysis.data_manipulation.NormalizationType.NormalizationType, reads: immuneML.util.ReadsType.ReadsType, sequence_encoding: immuneML.encodings.kmer_frequency.sequence_encoding.SequenceEncodingType.SequenceEncodingType, k: int = 0, k_left: int = 0, k_right: int = 0, min_gap: int = 0, max_gap: int = 0, metadata_fields_to_include: Optional[list] = None, name: Optional[str] = None, scale_to_unit_variance: bool = False, scale_to_zero_mean: bool = False, sequence_type: Optional[immuneML.environment.SequenceType.SequenceType] = None)[source]

Bases: immuneML.encodings.kmer_frequency.KmerFrequencyEncoder.KmerFrequencyEncoder

encode_repertoire(repertoire, params: immuneML.encodings.EncoderParams.EncoderParams)[source]
get_encoded_repertoire(repertoire, params: immuneML.encodings.EncoderParams.EncoderParams)[source]

immuneML.encodings.kmer_frequency.KmerFreqSequenceEncoder module

class immuneML.encodings.kmer_frequency.KmerFreqSequenceEncoder.KmerFreqSequenceEncoder(normalization_type: immuneML.analysis.data_manipulation.NormalizationType.NormalizationType, reads: immuneML.util.ReadsType.ReadsType, sequence_encoding: immuneML.encodings.kmer_frequency.sequence_encoding.SequenceEncodingType.SequenceEncodingType, k: int = 0, k_left: int = 0, k_right: int = 0, min_gap: int = 0, max_gap: int = 0, metadata_fields_to_include: Optional[list] = None, name: Optional[str] = None, scale_to_unit_variance: bool = False, scale_to_zero_mean: bool = False, sequence_type: Optional[immuneML.environment.SequenceType.SequenceType] = None)[source]

Bases: immuneML.encodings.kmer_frequency.KmerFrequencyEncoder.KmerFrequencyEncoder

immuneML.encodings.kmer_frequency.KmerFrequencyEncoder module

class immuneML.encodings.kmer_frequency.KmerFrequencyEncoder.KmerFrequencyEncoder(normalization_type: immuneML.analysis.data_manipulation.NormalizationType.NormalizationType, reads: immuneML.util.ReadsType.ReadsType, sequence_encoding: immuneML.encodings.kmer_frequency.sequence_encoding.SequenceEncodingType.SequenceEncodingType, k: int = 0, k_left: int = 0, k_right: int = 0, min_gap: int = 0, max_gap: int = 0, metadata_fields_to_include: Optional[list] = None, name: Optional[str] = None, scale_to_unit_variance: bool = False, scale_to_zero_mean: bool = False, sequence_type: Optional[immuneML.environment.SequenceType.SequenceType] = None)[source]

Bases: immuneML.encodings.DatasetEncoder.DatasetEncoder

The KmerFrequencyEncoder class encodes a repertoire, sequence or receptor by frequencies of k-mers it contains. A k-mer is a sequence of letters of length k into which an immune receptor sequence can be decomposed. K-mers can be defined in different ways, as determined by the sequence_encoding.

Parameters
  • sequence_encoding (SequenceEncodingType) – The type of k-mers that are used. The simplest sequence_encoding is CONTINUOUS_KMER, which uses contiguous subsequences of length k to represent the k-mers. When gapped k-mers are used (GAPPED_KMER, GAPPED_KMER), the k-mers may contain gaps with a size between min_gap and max_gap, and the k-mer length is defined as a combination of k_left and k_right. When IMGT k-mers are used (IMGT_CONTINUOUS_KMER, IMGT_GAPPED_KMER), IMGT positional information is taken into account (i.e. the same sequence in a different position is considered to be a different k-mer). When the identity representation is used (IDENTITY), the k-mers just correspond to the original sequences.

  • normalization_type (NormalizationType) – The way in which the k-mer frequencies should be normalized. The default value for normalization_type is l2.

  • reads (ReadsType) – Reads type signify whether the counts of the sequences in the repertoire will be taken into account. If UNIQUE, only unique sequences (clonotypes) are encoded, and if ALL, the sequence ‘count’ value is taken into account when determining the k-mer frequency. The default value for reads is unique.

  • k (int) – Length of the k-mer (number of amino acids) when ungapped k-mers are used. The default value for k is 3.

  • k_left (int) – When gapped k-mers are used, k_left indicates the length of the k-mer left of the gap. The default value for k_left is 1.

  • k_right (int) – Same as k_left, but k_right determines the length of the k-mer right of the gap. The default value for k_right is 1.

  • min_gap (int) – Minimum gap size when gapped k-mers are used. The default value for min_gap is 0.

  • max_gap – (int): Maximum gap size when gapped k-mers are used. The default value for max_gap is 0.

  • sequence_type (SequenceType) – Whether to work with nucleotide or amino acid sequences. Amino acid sequences are the default. To work with either sequence type, the sequences of the desired type should be included in the datasets, e.g., listed under ‘columns_to_load’ parameter. By default, both types will be included if available. Valid values are: AMINO_ACID and NUCLEOTIDE.

  • scale_to_unit_variance (bool) – whether to scale the design matrix after normalization to have unit variance per feature. Setting this argument to True might improve the subsequent classifier’s performance depending on the type of the classifier. The default value for scale_to_unit_variance is true.

  • scale_to_zero_mean (bool) – whether to scale the design matrix after normalization to have zero mean per feature. Setting this argument to True might improve the subsequent classifier’s performance depending on the type of the classifier. However, if the original design matrix was sparse, setting this argument to True will destroy the sparsity and will increase the memory consumption. The default value for scale_to_zero_mean is false.

YAML specification:

my_continuous_kmer:
    KmerFrequency:
        normalization_type: RELATIVE_FREQUENCY
        reads: UNIQUE
        sequence_encoding: CONTINUOUS_KMER
        sequence_type: NUCLEOTIDE
        k: 3
        scale_to_unit_variance: True
        scale_to_zero_mean: True
my_gapped_kmer:
    KmerFrequency:
        normalization_type: RELATIVE_FREQUENCY
        reads: UNIQUE
        sequence_encoding: GAPPED_KMER
        sequence_type: AMINO_ACID
        k_left: 2
        k_right: 2
        min_gap: 1
        max_gap: 3
        scale_to_unit_variance: True
        scale_to_zero_mean: False
STEP_ENCODED = 'encoded'
STEP_NORMALIZED = 'normalized'
STEP_SCALED = 'scaled'
STEP_VECTORIZED = 'vectorized'
static build_object(dataset=None, **params)[source]
dataset_mapping = {'ReceptorDataset': 'KmerFreqReceptorEncoder', 'RepertoireDataset': 'KmerFreqRepertoireEncoder', 'SequenceDataset': 'KmerFreqSequenceEncoder'}
encode(dataset, params: immuneML.encodings.EncoderParams.EncoderParams)[source]
static export_encoder(path: pathlib.Path, encoder) pathlib.Path[source]
get_additional_files() List[str][source]
static load_encoder(encoder_file: pathlib.Path)[source]
scale_normalized(params, dataset, normalized_examples)[source]

immuneML.encodings.kmer_frequency.ReadsType module

Module contents