icbi-lab / infercnvpy

Infer copy number variation (CNV) from scRNA-seq data. Plays nicely with Scanpy.

Home Page:https://infercnvpy.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

considering numerically order the chromosome label `chr_pos` on the `chromosome_heatmap` function?

jingxinfu opened this issue · comments

There is no reordering on chr_pos

ref: line 58 infercnvpy/infercnvpy/pl/_chromosome_heatmap.py

chr_pos = list(adata.uns[use_rep]["chr_pos"].values())

I follow the tutorial to get the CNV profile.
And the original order of the adata.uns['cnv']["chr_pos"]was

{'chr1': 0,
 'chr10': 1619,
 'chr11': 1749,
 'chr12': 1937,
...
 'chr5': 868,
 'chr6': 1034,
 'chr7': 1205,
 'chr8': 1362,
 'chr9': 1498}

the chromosome labels are not correctly displayed on the heatmap.

Hi @jingxinfu,

thanks for your feedback!
This shouldn't happen as the chr_pos dict gets sorted here:

chromosomes = _natural_sort(
[x for x in var["chromosome"].unique() if x.startswith("chr") and x != "chrM"]
)

Could you please report this additional information:

  • your Python version and cnv.__version__
  • list(adata.var["chromosome"].unique())
  • cnv.tl._infercnv._natural_sort(adata.var["chromosome"].unique())

Cheers,
Gregor

Hi gregor,

Thanks for your quick response!
Below are my outputs:

  • cnv.__version__: 0.1.0.
  • list(adata.var["chromosome"].unique())
 nan,
 'chr2',
 'chr3',
 'chr4',
 'chr5',
 'chr6',
 'chr7',
 'chr8',
 'chr9',
 'chr10',
 'chr11',
 'chr12',
 'chr13',
 'chr14',
 'chr15',
 'chr16',
 'chr17',
 'chr18',
 'chr19',
 'chr20',
 'chr21',
 'chr22',
 'chrX',
 'chrY',
 'chrM']
  • cnv.tl._infercnv._natural_sort(adata.var["chromosome"].unique())
~/miniconda3/envs/scrna/lib/python3.8/re.py in split(pattern, string, maxsplit, flags)
    229     and the remainder of the string is returned as the final element
    230     of the list."""
--> 231     return _compile(pattern, flags).split(string, maxsplit)
    232 
    233 def findall(pattern, string, flags=0):
TypeError: expected string or bytes-like object

What happened to your chr1?

Apart from that, there's nothing unexpected here. Could you please also try

tmp_adata = adata[:, ~adata.var["chromosome"].isnull()]
cnv.tl._infercnv._natural_sort(tmp_adata.var["chromosome"].unique())

to deal with the NAs (which infercnvpy already should)

apologize for the mistake, there should be chr1 in that list. I didn't paste the whole list.
and following is my output of your cmds:

array(['chr1', 'chr2', 'chr3', 'chr4', 'chr5', 'chr6', 'chr7', 'chr8',
       'chr9', 'chr10', 'chr11', 'chr12', 'chr13', 'chr14', 'chr15',
       'chr16', 'chr17', 'chr18', 'chr19', 'chr20', 'chr21', 'chr22',
       'chrM', 'chrX', 'chrY'], dtype=object)

which looks good.

Does it mean that I should manually remove NAs in chromosome before running infercnv?

Did you, by any chance, save & load the anndata object between running tl.infercnv and plotting?
At least by doing so, I can reproduce your problem, as after reloading, adata.uns["cnv"] does not have the original order anymore.

thanks for your help! I reordered the chromosome, now the labels display correctly.

Anyway, this should be fixed now in the latest master branch.
The heatmap should now render fine, even with an unordered dictionary.

You can install it using

pip install git+https://github.com/icbi-lab/infercnvpy.git@master

Can you confirm that this solved the problem?

yes, it did.

perfect, thanks for checking!