Assigning mitocondrial genes variable
In my dataset the mitocondrial genes are not all labeled with 'mt-', some of them are like 'NC_002333.23, NC_002333.24', for example. I have a txt file with all the mitocondrial genes and I have loaded it into the notebook with
x = open('michondrialgenesDR11.txt', 'r') mitogenes = x.read()
I am searching now for a command to annonate the group of genes in the txt file as adata.var['mt']. Could you please help? Thank you!
Assuming genes in your text file are newline separated like this:
NC_002333.23
NC_002333.24
This will work:
with open("michondrialgenesDR11.txt", "r") as f:
mtgenes = set((i.strip() for i in f.readlines()))
adata.var["mt"] = adata.var.index.isin(mtgenes)
adata.var
list also would be ok because set won't make much of a difference with presumably 13 genes.
I hope this answers your question. It is more of a python question than a sc-rnaseq one, so you'd probably want to get more familiar with the language
cheers