Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with AnchoredGTFDl #102

Open
PelFritz opened this issue Aug 31, 2021 · 3 comments
Open

Error with AnchoredGTFDl #102

PelFritz opened this issue Aug 31, 2021 · 3 comments
Assignees

Comments

@PelFritz
Copy link

Hi,
I am using AnchoredGTFDl to extract promoter sequences, however when I call the load_all() I get the following error
"ValueError: all input arrays must have the same shape".

My assumption is that this arises from the fact that some gene coordinates are too close to the end of the chromosome and hence we do not get the appropriate extraction length. My code is below

`import numpy as np
from kipoiseq.dataloaders import AnchoredGTFDl

fasta_path = 'Zea_mays.Zm-B73-REFERENCE-NAM-5.0.dna.toplevel.fa'
gtf_path = 'Zea_mays.Zm-B73-REFERENCE-NAM-5.0.51.gtf'

dl = AnchoredGTFDl(gtf_path, fasta_path, num_upstream=1000, num_downstream=500,
gtf_filter='gene_biotype == "protein_coding"')

data = dl.load_all()`

As a work around I used the code below but I don't know if this is okay or there is some function to check extracted sequence length automatically.

`sequence = []
gene_id = []
for seq in dl:
if len(seq['inputs']) == 1500:
gene_id.append(seq['metadata']['gene_id'])
sequence.append(seq['inputs'])

sequence = np.array(sequence)
print(sequence.shape)`

Is there some way to assert sequence length to be the same?

@Hoeze
Copy link
Member

Hoeze commented Sep 2, 2021

Hi @PelFritz, thanks for posting this issue.

I think there are two valid solutions for this issue:

  • Pad sequences with N's
  • Filter too short sequences

This should be done here I guess:

sequence = self._fa.extract(interval)

@Karollus What's your opinion?

@Karollus
Copy link
Collaborator

Sorry for the very late reply, I somehow missed this.

I think the most feasible solution (without changing the behaviour of the extract function- which would impact a lot of dataloaders) is to have a padding or filtering afterwards. This is a bit ugly - it runs a check for every extracted sequence, but I see no other real solution. I think N-padding is probably better than filtering (filtering can be done by done relatively easily by the user by excluding genes too close to the chromosome end, padding is harder to achieve for the user as it requires editing the fasta - so it seems that providing padding would be more useful). @Hoeze, does that sound reasonable?

I can try to prototype it in the next few days

@Hoeze
Copy link
Member

Hoeze commented Oct 14, 2021

@Karollus maybe we can have an additional flag in the dataloader that chooses the behavior:
a) raise an error
b) log a warning and just remove the sequence
c) silently pad the sequence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants