broadinstitute / tensorqtl

Ultrafast GPU-enabled QTL mapper
BSD 3-Clause "New" or "Revised" License
162 stars 52 forks source link

Catch and pass on exceptions from background generators. #140

Closed kshakir closed 3 months ago

kshakir commented 5 months ago

Resolves #139.

New stack trace that exits instead of the main thread getting stuck:

Warning: 'rfunc' cannot be imported. R with the 'qvalue' library and the 'rpy2' Python package are needed to compute q-values.
[Jun 18 11:54:09] Running TensorQTL v1.0.9: cis-QTL mapping
  * WARNING: using CPU!
  * using seed 777
  * reading phenotypes (single_uniform_expression.phenotype.bed)
  * cis-window detected as position ± 1,000,000
  * loading genotypes
cis-QTL mapping: nominal associations for all variant-phenotype pairs
  * 3 samples
  * 1 phenotypes
  * 1 variants
  * cis-window: ±1,000,000
    ** dropping 1 constant phenotypes
  * Computing associations
    Mapping chromosome chr1
Traceback (most recent call last):
  File "/Users/kshakir/miniconda3/envs/tensorqtl/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/kshakir/miniconda3/envs/tensorqtl/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/kshakir/src/tensorqtl/tensorqtl/__main__.py", line 2, in <module>
    tensorqtl.main()
  File "/Users/kshakir/src/tensorqtl/tensorqtl/tensorqtl.py", line 180, in main
    cis.map_nominal(genotype_df, variant_df, phenotype_df, phenotype_pos_df, args.prefix, covariates_df=covariates_df,
  File "/Users/kshakir/src/tensorqtl/tensorqtl/cis.py", line 256, in map_nominal
    for k, (phenotype, genotypes, genotype_range, phenotype_id) in enumerate(igc.generate_data(chrom=chrom, verbose=verbose), k+1):
  File "/Users/kshakir/src/tensorqtl/tensorqtl/genotypeio.py", line 68, in __next__
    return self.next()
  File "/Users/kshakir/src/tensorqtl/tensorqtl/genotypeio.py", line 64, in next
    raise next_item
  File "/Users/kshakir/src/tensorqtl/tensorqtl/genotypeio.py", line 51, in run
    for item in self.generator:
  File "/Users/kshakir/src/tensorqtl/tensorqtl/genotypeio.py", line 496, in generate_data
    chr_offset = offset_dict[chrom]
KeyError: 'chr1'

Process finished with exit code 1
francois-a commented 3 months ago

Thank you for catching this and submitting the fix!