# Error in quantile.default(x, p = p) in EgdeR calcNormFactors

I am trying to run TMM normalization using rpy2 and when I run calcNormFactors() function:

dge_list = edgeRLib.DGEList(counts=rawcounts)
dge_list = edgeRLib.calcNormFactors(dge_list, method="TMM")


I am getting the error:

RRuntimeError: Error in quantile.default(x, p = p) : missing values and NaN's not allowed if 'na.rm' is FALSE

So, I thought that maybe my rawcounts 2D numpy array contains nan values but it does not. I checked it with both pd.isnull() and np.isnan() functions. So, I suspect now that the 2D array itself can not be normalized for some reason and I do not know why. The error is most probably not related to rpy2 set up and R installation because it was working before for similar numpy arrays but failed this time. Any suggestions would be greatly appreciated.

Ok, it turned out that some rows and/or columns contained all values as zeros and that was the reason for the error. I wrote a function to fix that:

def fix_rawcounts(rawcounts, cell_ids, gene_symbols):
'''The function checks whether there are
any rows or columns with all zeros
and removes them'''
print('Checking whether rows or columns contain all zeros')

# Checking columns
count_arr = np.apply_along_axis(np.count_nonzero, axis=0, arr=rawcounts )
rawcounts = rawcounts[:,count_arr != 0]

# Checking rows
count_arr = np.apply_along_axis(np.count_nonzero, axis=1, arr=rawcounts )
rawcounts = rawcounts[count_arr != 0,:]

print('finished checking zero rows and columns')
return rawcounts