openvax / pyensembl

Python interface to access reference genome features (such as genes, transcripts, and exons) from Ensembl
Apache License 2.0
365 stars 66 forks source link

Error when running top_priority_effect() second time in pyramid webapp #248

Open pajanne opened 3 years ago

pajanne commented 3 years ago

I am facing a strange error when running top_priority_effect() for the second time in my Pyramid WebApp using an SQLite back-end database:

var = Variant(contig=contig, start=start, ref=ref, alt=alt, ensembl=genome)
top_effect = var.effects().top_priority_effect()
consequence = top_effect.__class__.__name__

I've tried running adding genome.clear_cache() before but without any success. Please find below the error message I get:

Traceback (most recent call last):
  File "/Users/pajanne/workspace/GenEditID-test2projects/python/geneditid/plotter.py", line 195, in get_variant_classification
    top_effect = var.effects().top_priority_effect()
  File "/Users/pajanne/workspace/GenEditID-test2projects/venv/lib/python3.8/site-packages/varcode/variant.py", line 451, in effects
    return predict_variant_effects(
  File "/Users/pajanne/workspace/GenEditID-test2projects/venv/lib/python3.8/site-packages/varcode/effects/effect_prediction.py", line 66, in predict_variant_effects
    gene_ids = variant.gene_ids
  File "/Users/pajanne/workspace/GenEditID-test2projects/venv/lib/python3.8/site-packages/varcode/variant.py", line 423, in gene_ids
    self._gene_ids = self.genome.gene_ids_at_locus(
  File "/Users/pajanne/workspace/GenEditID-test2projects/venv/lib/python3.8/site-packages/pyensembl/genome.py", line 538, in gene_ids_at_locus
    return self.db.distinct_column_values_at_locus(
  File "/Users/pajanne/workspace/GenEditID-test2projects/venv/lib/python3.8/site-packages/pyensembl/database.py", line 402, in distinct_column_values_at_locus
    return self.column_values_at_locus(
  File "/Users/pajanne/workspace/GenEditID-test2projects/venv/lib/python3.8/site-packages/pyensembl/database.py", line 358, in column_values_at_locus
    tuples = self.connection.execute(query, query_params).fetchall()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 123145447256064 and this is thread id 123145464045568.

The only way to make it works so far is to restart the webapp each time I wish to run this code. There must be something better to do to avoid this error message. Please let me know. Many thanks.