eugene.models.init_motif_weights

eugene.models.init_motif_weights(model, layer_name, motifs, list_index=None, initializer='kaiming_normal', convert_to_pwm=True, divide_by_bg=True, motif_align='center', kernel_align='center')

Initialize the convolutional kernel of choice using a set of motifs

This function is designed to initialize the convolutional kernels of a given layer of a model with a set of motifs. It has only been tested on nn.Conv1d layers and ParameterList layers that have a shape of (num_kernels, 4, kernel_size). Simply use the named module of the layer you want to initialize and pass it to this function. If the layer is a ParameterList, you must also pass the index of the kernel you want to initialize. If the layer is a Conv1d layer, you can pass None as the index.

This function modifies the model in place.

Parameters:
  • model (Module) – The model to initialize.

  • layer_name (str) – The name of the layer to initialize. You can use the list_available_layers function to get a list of available layers.

  • motifs (MotifSet) – A MotifSet object containing the motifs to initialize the kernel with. MotifSets are from the package motifdata.

  • list_index (int, optional) – The index of the kernel to initialize. Only required if the layer is a ParameterList layer, by default None

  • initializer (str, optional) – The name of the initializer to use, by default “kaiming_normal”

  • convert_to_pwm (bool, optional) – Whether to convert the kernel to a PWM after initializing, by default True

  • divide_by_bg (bool, optional) – Whether to divide the kernel by the background frequencies after initializing, by default True

  • motif_align (Literal["center", "left", "right"], optional) – How to align the motifs when converting to a PWM, by default “center”

  • kernel_align (Literal["center", "left", "right"], optional) – How to align the kernel when converting to a PWM, by default “center”

Return type:

None

Examples

>>> from eugene import models
>>> from motifdata import MotifSet
>>> model = models.zoo.DeepSTARR(input_len=1000, output_dim=1)
>>> motifs = MotifSet("path/to/motifs.txt")
>>> list_available_layers(model)
>>> init_motif_weights(model, "conv1d_tower.layers.0", motifs)