I do not know python at all thus I have been unsuccessful in interpreting similar previous answers and using them.
I have a python script that I wish to execute in unix. The script uses an input file but I do not understand how to ensure that the input file is read as numpy float array.
My input file is called chk.bed and it has one column of numeric values
-bash-4.1$ # head chk.bed
7.25236
0.197037
0.189464
2.60056
0
32.721
11.3978
3.85692
0
0
The original script is -
from scipy.stats import gaussian_kde
import numpy as np
#assume "fpkm" is a NumPy array of log2(fpkm) values
kernel = gaussian_kde(fpkm)
xi = np.linspace(fpkm.min(), fpkm.max(), 100)
yi = kernel.evaluate(xi)
mu = xi[np.argmax(yi)]
U = fpkm[fpkm > mu].mean()
sigma = (U - mu) * np.sqrt(np.pi / 2)
zFPKM = (fpkm - mu) / sigma
What I could understand up until now is to make sure the script is reading the file so I included fpkm = open("chk.bed", 'r') in the code.
However on executing the code - I get the following error -
Traceback (most recent call last):
File "./calc_zfpkm.py", line 10, in <module>
kernel = gaussian_kde(fpkm)
File "/usr/lib64/python2.6/site-packages/scipy/stats/kde.py", line 88, in __init__
self._compute_covariance()
File "/usr/lib64/python2.6/site-packages/scipy/stats/kde.py", line 340, in _compute_covariance
self.factor * self.factor)
File "/usr/lib64/python2.6/site-packages/numpy/lib/function_base.py", line 1971, in cov
X = array(m, ndmin=2, dtype=float)
TypeError: float() argument must be a string or a number
This seems to suggest that I am not reading in the file correctly and so the function gaussian_kde() cannot read in the values as float.
Can you please help ?
Thanks !