aboutsummaryrefslogtreecommitdiff
path: root/kmer.py
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2014-02-05 14:37:43 -0500
committerCalvin Morrison <mutantturkey@gmail.com>2014-02-05 14:37:43 -0500
commit6fad94ac730598ca83794c6874a5a7648e9ab811 (patch)
treeea244f115db6db5949beacd30768c7b159fe27cd /kmer.py
parent591fb2ff04a64c7c3d08dee5f0efcb32c7775950 (diff)
add example, rename variables, rename function, improve error function, check for types
Diffstat (limited to 'kmer.py')
-rw-r--r--kmer.py23
1 files changed, 18 insertions, 5 deletions
diff --git a/kmer.py b/kmer.py
index c22ec1e..1774f5f 100644
--- a/kmer.py
+++ b/kmer.py
@@ -20,19 +20,32 @@ try:
except:
raise Exception("Error: could not load libkmer.so")
-def load_kmer_counts_from_file(fh, kmer):
+def get_counts_from_file(fn, kmer):
'''
+ load kmer counts from a filename (not a handle), of size kmer.
+
+returns an array size 4^k of counts
+
+ >>> import kmer
+ >>> counts = kmer.get_counts_from_file("test.fa", 6)
+
'''
+
+ if type(fn) is not str:
+ raise TypeError("fn must be a str");
+ if type(kmer) is not int:
+ raise TypeError("fn must be int");
+
ret = []
- width = (kmer ** 4) + 1
+ width = (kmer ** 4)
libkmer.get_kmer_counts_from_filename.restype = c.POINTER(c.c_ulonglong * width )
- counts = libkmer.get_kmer_counts_from_filename(fh, kmer);
+ counts = libkmer.get_kmer_counts_from_filename(fn, kmer);
- if counts.contents:
+ if counts:
for i in counts.contents:
ret.append(i)
else:
- ret = 'error'
+ ret = 'error could not count mers on' + str(fn)
return ret