Echo94
Echo94

Reputation: 13

I am getting an error for a scanpy package when running it as bash script

I am encountering an error when I trying to save a scanpy results file on a cluster. One of the steps causes Jupyter kernel to crash because it takes a lot of memory. So in order to combat this I am trying to do that on the cluster and for that I need to save file just before that point, which works just fine on my computer using:

adata_combined.write_h5ad("adata_combined_regress.h5ad") or adata_combined.write("adata_combined_regress.h5ad")

but if I am running the subsequent steps on cluster, I get an error

"AttributeError: 'NoneType' object has no attribute 'write_h5ad' or if I just use .write "AttributeError: 'NoneType' object has no attribute 'write'

My python script for the cluster is:

#!/Users/k01/miniconda3/envs/scrna/bin/python regress_scanpy.py
 
#! This file represents a very simple header header that you can use as the
#! basis for your own jobs. Copy this file and amend it.
 
#!#############################################################
#!#### Modify the options in this section as appropriate ######
#!#############################################################
 
#! Give your job a name
#SBATCH -J cpujob
#! How many cores per task?
#SBATCH --cpus-per-task=20
#! How much memory do you need?
#SBATCH --mem=32G
#! How much wallclock time will be required?
#SBATCH --time=20:00:00
#! What types of email messages do you wish to receive?
#SBATCH --mail-type=ALL
#! Specify your email address here otherwise you won't recieve emails!
#SBATCH --mail-user=k01@
#! Uncomment this to prevent the job from being requeued (e.g. if
#! interrupted by node failure or system downtime):
##SBATCH --no-requeue
#! General partition
#SBATCH -p general


import numpy as np
import pandas as pd
import scanpy as sc
import scipy


adata_comb = sc.read_h5ad('/mnt/k01/ScRNA_scanpy/adata_combined.h5ad')
adata_comb_regressed = sc.pp.regress_out(adata_comb, ['total_counts', 'pct_counts_mt']) 
adata_comb_regressed.write_h5ad('/mnt/k01/ScRNA_scanpy/adata_comb_regressed_new.h5ad')

Upvotes: 0

Views: 260

Answers (1)

nobot
nobot

Reputation: 93

sc.pp.regress_out function does not return anything unless you give the copy=True parameter as

adata_comb_regressed = sc.pp.regress_out(adata_comb, ['total_counts', 'pct_counts_mt'], copy=True)

If you don't want to make copy, you can do

import numpy as np
import pandas as pd
import scanpy as sc
import scipy


adata_comb = sc.read_h5ad('/mnt/k01/ScRNA_scanpy/adata_combined.h5ad')
sc.pp.regress_out(adata_comb, ['total_counts', 'pct_counts_mt']) 
adata_comb.write_h5ad('/mnt/k01/ScRNA_scanpy/adata_comb_regressed_new.h5ad')

Upvotes: 0

Related Questions