broadinstitute / tensorqtl

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

cis-mapping with interaction #138

Open SynaSpike opened 4 months ago

SynaSpike commented 4 months ago

Hello,

It has been a while now that I am using this powerful tool which is tensorqtl so thanks for the work. Recently, I'have tried to perform a cis-mapping with an interaction term (which is the sex). I am using the exact same data as GTEx V8. Looking up at the thyroid, I encountered this error :

cis_df_thyroid_sex_binary = cis.map_nominal(genotype_df, variant_df, phenotype_df,phenotype_pos_df, prefix = "thyroid_sb_eqtl", covariates_df=thyroid_covariates_filter, interaction_df=sex_df)


_LinAlgError Traceback (most recent call last) File ~/.local/lib/python3.8/site-packages/tensorqtl/core.py:197, in calculate_interaction_nominal(genotypes_t, phenotypes_t, interaction_t, residualizer, return_sparse, tstat_threshold, variant_ids) 196 try: --> 197 Xinv = torch.matmul(torch.transpose(X_t, 1, 2), X_t).inverse() # ng x (1+2ni) x (1+2ni) 198 except Exception as e:

_LinAlgError: linalg.inv: (Batch element 1232): The diagonal element 3 is zero, the inversion could not be completed because the input matrix is singular.

During handling of the above exception, another exception occurred:

IndexError Traceback (most recent call last) Cell In[8], line 2 1 # Run permutations with sex-biased ----> 2 cis_df_thyroid_sex_binary = cis.map_nominal(genotype_df, variant_df, phenotype_df,phenotype_pos_df, prefix = "thyroid_sb_eqtl", 3 covariates_df=thyroid_covariates_filter, interaction_df=sex_df)

File ~/.local/lib/python3.8/site-packages/tensorqtl/cis.py:294, in map_nominal(genotype_df, variant_df, phenotype_df, phenotype_pos_df, prefix, covariates_df, paired_covariate_df, maf_threshold, interaction_df, maf_threshold_interaction, group_s, window, run_eigenmt, output_dir, write_top, write_stats, logger, verbose) 292 mask = mask_t.cpu().numpy() 293 variant_ids = variant_ids[mask] --> 294 res = calculate_interaction_nominal(genotypes_t, phenotype_t.unsqueeze(0), interaction_t, 295 residualizer=iresidualizer, return_sparse=False, 296 variant_ids=variant_ids) 297 tstat, b, b_se, af, ma_samples, ma_count = [i.cpu().numpy() for i in res] 298 start_distance = start_distance[mask]

File ~/.local/lib/python3.8/site-packages/tensorqtl/core.py:200, in calculate_interaction_nominal(genotypes_t, phenotypes_t, interaction_t, residualizer, return_sparse, tstat_threshold, variant_ids) 198 except Exception as e: 199 if variant_ids is not None and len(e.args) >= 1: --> 200 i = int(re.findall('For batch (\d+)', str(e))[0]) 201 e.args = (e.args[0] + f'\n Likely problematic variant: {variant_ids[i]} ',) + e.args[1:] 202 raise

IndexError: list index out of range

I have seen that this could be due to a genotype dosage error and it was recommended to remove HOM_REF_CT < 10 (#107). But even after the removal I still encountered the error.

Do you have a hint ?

Thanks in advance

francois-a commented 4 weeks ago

This part of the error suggests that there is colinearity between sex and the genotype dosages: "The diagonal element 3 is zero, the inversion could not be completed because the input matrix is singular". Can you check whether that's the case?