Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpy import error #1

Open
ranijames opened this issue Jan 22, 2021 · 2 comments
Open

Numpy import error #1

ranijames opened this issue Jan 22, 2021 · 2 comments

Comments

@ranijames
Copy link

Hi All,
I am trying to extract features from a given fasta file (DNA or RNA), using kmer.py script as per the description in the README. While running the code in a juypter notebook it is throwing the following error.

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-11-1066287f4a62> in <module>
      4 
      5 k   = 6  # choose the value for k
----> 6 obj = kmer_featurization(k)
      7 kmer_features = obj.obtain_kmer_feature_for_a_list_of_sequences(seq_list, write_number_of_occurrences=False)

~/Documents/lncRNAs_project_2020/scripts_2021/kmer/kmer.py in __init__(self, k)
      8     """
      9     self.k = k
---> 10     self.letters = ['A', 'T', 'C', 'G']
     11     self.multiplyBy = 4 ** np.arange(k-1, -1, -1) # the multiplying number for each digit position in the k-number system
     12     self.n = 4**k # number of possible k-mers

NameError: name 'np' is not defined

I am running the script in python 3.2.7, and I have numpy installed.
This is how I tried running the script,

from kmer import kmer_featurization 
import numpy as np
seq_list = ['ATCGA', 'TCGAC']  # a list of DNA sequences

k   = 6  # choose the value for k
obj = kmer_featurization(k) 
kmer_features = obj.obtain_kmer_feature_for_a_list_of_sequences(seq_list, write_number_of_occurrences=False)

Any suggestions/help is much appreciated!

@AhmadObeid
Copy link

Add import numpy as np at the top of kmer.py

@Azeem-svg
Copy link

Hi All,
I tried this code , this worked but gave an error
PS C:\Users\Azeem Javed\Desktop\python_ammar.py\BMI and visulization> & "C:/Users/Azeem Javed/AppData/Local/Programs/Python/Python310/python.exe"
"c:/Users/Azeem Javed/Desktop/python_ammar.py/BMI and visulization/kmer.py"
c:\Users\Azeem Javed\Desktop\python_ammar.py\BMI and visulization\kmer.py:51: RuntimeWarning: invalid value encountered in true_divide
kmer_feature = kmer_feature / number_of_kmers

Actually i want to make kmers from a genome of bacteria (have seq file in FASTA format), Is it a right code to do so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants