BIMSBbioinfo / janggu

Deep learning infrastructure for genomics
GNU General Public License v3.0
254 stars 33 forks source link

Index Error: tuple index out of range #28

Closed starboyvarun closed 3 years ago

starboyvarun commented 3 years ago
from keras.layers import Conv2D
from keras.layers import AveragePooling2D
from janggu import inputlayer
from janggu import outputconv
from janggu import DnaConv2D
from janggu.data import ReduceDim
from keras.layers import GlobalAveragePooling2D   #Added later

# load the dataset which consists of
# 1) a reference genome
REFGENOME = resource_filename('janggu', 'resources/pseudo_genome.fa')
# 2) ROI contains regions spanning positive and negative examples
ROI_FILE = resource_filename('janggu', 'resources/roi_train.bed')
# 3) PEAK_FILE only contains positive examples
PEAK_FILE = resource_filename('janggu', 'resources/scores.bed')

# DNA sequences are loaded directly from the reference genome
DNA = Bioseq.create_from_refgenome('dna', refgenome=REFGENOME,
                                   roi=ROI_FILE,
                                   binsize=200)

# Classification labels over the same regions are loaded
# into the Coverage dataset.
# It is important that both DNA and LABELS load with the same
# binsize, stepsize to ensure
# the correct correspondence between both datasets.
# Finally, the ReduceDim dataset wrapper transforms the 4D Coverage
# object into a 2D table like object (regions by conditions)

LABELS = ReduceDim(Cover.create_from_bed('peaks', roi=ROI_FILE,
                               bedfiles=PEAK_FILE,
                               binsize=200,
                               resolution=None), aggregator='mean')

# 2. define a simple conv net with 30 filters of length 15 bp
# and relu activation.
# outputconv as opposed to outputdense will put a conv layer as output
@inputlayer
@outputdense('sigmoid')
def double_stranded_model(inputs, inp, oup, params):
    with inputs.use('dna') as layer:
        # The DnaConv2D wrapper can be used with Conv2D
        # to scan both DNA strands with the weight matrices.
        layer = DnaConv2D(Conv2D(params[0], (params[1], 1),
                                 activation=params[2]))(layer)

    output = GlobalAveragePooling2D(name='motif')(layer)
    return inputs, output

# 3. instantiate and compile the model
model = Janggu.create(template=double_stranded_model,
                      modelparams=(30, 15, 'relu'),
                      inputs=DNA, outputs=ReduceDim(LABELS))
model.compile(optimizer='adadelta', loss='binary_crossentropy',
              metrics=['acc'])

# 4. fit the model
model.fit(DNA, ReduceDim(LABELS), epochs=100)

9 1

9 1

Hello @rekado , This Error is related to janngu , please can you tell me what's wrong here. It would be much help. Thank you.

wkopp commented 3 years ago

Can you post a minimal example of the code that can reproduce the error. Your example does not work. Several imports are missing. Also, indicate if you used one of the examples scripts contained in janggu as template. Check if the example scripts are working properly and, if applicable, clearly explain what you have modified in order to obtain the error.

starboyvarun commented 3 years ago

Hello @wkopp This code is taken from Janggu documentation PART 2 on Fit a neural network on DNA sequences. Examples 1,2,3 work fine of PART 2 of the Janggu documentation. I haven't modified anything major here just the syntax error like EOF etc and added packages. The code is a snippet of Fit a neural network on DNA sequences from janggu documentation.

Minimal example of the code :

0 1

This is the full Error which is showing:

1 2

I checked running example classify_fasta.py it is running perfectly fine. And I am not trying to run an example I am trying to implement code from the Janggu documentation as mentioned above. Now please tell me why this error is showing.

EDIT 1: I tried modify the code its runs: 3' Can you Please tell whether is giving the Right result? For particular code? Thanks!

wkopp commented 3 years ago

Thank you, @starboyvarun . Yes, there was an issue in the example. ReduceDim(LABELS) should have been only LABELS. This caused the issue, because LABELS was already wrapped with ReduceDim earlier in the tutorial.

starboyvarun commented 3 years ago

Welcome, @wkopp. Please can you accept the patch1 I have created? I edited the code from where I have been doing it. Enjoy your vacation. Thank you.