MultiGenerator

Introduction

MultiGenerator is a class useful to train a model on several species at the same time or on both the positive and negative strands of the genome. It uses several datasets (Dataset) to generate batches of data that mix data coming from each dataset.

Creating an instance

To create an instance of MutliGenerator, create first the datasets involved and ensure that the shape of their inputs and their labels are all the same. The mandatory arguments are batch_size and dataset_list.

from keras_dna import SeqIntervalDl, MultiGenerator

dataset1 = SeqIntervalDl(fasta_file='species1.fa',
                         annotation_files=['ann1.gff'],
                         annotation_list=['binding site'])

### Same keyword except fasta and annotation file
dataset2 = SeqIntervalDl(fasta_file='species2.fa',
                         annotation_files=['ann2.gff'],
                         annotation_list=['binding site'])

generator = MultiGenerator(batch_size=64,
                           dataset_list=[dataset1, dataset2]) 

Warning : incoherent choice of dataset (a stringseq and a seq for instance) is not verified before processing and will lead to an error during training.

Changing labels shape

Use the keyword output_shape to readapt the labels' shape to your need (same principle as in Generator).

Changing the number of instances per dataset

To control the number of instances per dataset that the generator yields, use the keyword inst_per_dataset. The number of instances per dataset is passed through a list in the same order as the datasets in dataset_list. The default behaviour is to generate all the data available (which can leads to a bias toward one species).

from keras_dna import SeqIntervalDl, MultiGenerator

dataset1 = SeqIntervalDl(fasta_file='species1.fa',
                         annotation_files=['ann1.gff'],
                         annotation_list=['binding site'])

### Same keyword except fasta and annotation file
dataset2 = SeqIntervalDl(fasta_file='species2.fa',
                         annotation_files=['ann2.gff'],
                         annotation_list=['binding site'])

generator = MultiGenerator(batch_size=64,
                           dataset_list=[dataset1, dataset2],
                           inst_per_dataset=[10000, 10000])