MindAI / kmer

A Python code for generating k-mer features for a set of DNA/ genomic sequences.
28 stars 18 forks source link

Numpy import error #1

Open ranijames opened 3 years ago

ranijames commented 3 years ago

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 commented 3 years ago

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

Azeem-svg commented 2 years ago

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