Skip to content

Commit

Permalink
Renamed python module to dna_jellyfish. Deprecation not working.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarcais committed Dec 15, 2017
1 parent 1ad4b79 commit f9d25be
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 27 deletions.
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ AM_CONDITIONAL(PYTHON_BINDING, [test -n "$enable_python_binding" -a x$enable_pyt
AM_COND_IF([PYTHON_BINDING],
[AS_IF([test x$enable_python_binding != xyes], [PYTHON_SITE_PKG=$enable_python_binding])]
[AX_PYTHON_DEVEL([], [$prefix])])
AC_ARG_ENABLE([python-deprecated],
[AC_HELP_STRING([--enable-python-deprecated], [enable the deprecated 'jellyfish' module (in addition to 'dna_jellyfish')])])
AM_CONDITIONAL([PYTHON_DEPRECATED], [test -z "$enable_python_deprecated" -o x$enable_python_deprecated != xno])

# Ruby binding setup
AS_IF([test -z "$enable_ruby_binding"], [enable_ruby_binding="$enable_all_binding"])
Expand Down
22 changes: 13 additions & 9 deletions swig/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ endif

# Python support
if PYTHON_BINDING
PYTHON_BUILT = swig/python/swig_wrap.cpp swig/python/jellyfish.py
PYTHON_BUILT = swig/python/swig_wrap.cpp swig/python/dna_jellyfish.py
BUILT_SOURCES += $(PYTHON_BUILT)

pythonextdir = $(PYTHON_SITE_PKG)/jellyfish
if PYTHON_DEPRECATED
pythonglobaldir = $(PYTHON_SITE_PKG)
pythonglobal_SCRIPTS = swig/python/jellyfish.py
endif
pythonextdir = $(PYTHON_SITE_PKG)/dna_jellyfish
pythonext_SCRIPTS = swig/python/__init__.pyc
pythonext_LTLIBRARIES = swig/python/_jellyfish.la
swig_python__jellyfish_la_SOURCES = swig/python/swig_wrap.cpp $(SWIG_SRC)
swig_python__jellyfish_la_CPPFLAGS = $(PYTHON_CPPFLAGS) -I$(srcdir)/include
swig_python__jellyfish_la_LDFLAGS = -module
swig_python__jellyfish_la_LIBADD = libjellyfish-2.0.la
pythonext_LTLIBRARIES = swig/python/_dna_jellyfish.la
swig_python__dna_jellyfish_la_SOURCES = swig/python/swig_wrap.cpp $(SWIG_SRC)
swig_python__dna_jellyfish_la_CPPFLAGS = $(PYTHON_CPPFLAGS) -I$(srcdir)/include
swig_python__dna_jellyfish_la_LDFLAGS = -module
swig_python__dna_jellyfish_la_LIBADD = libjellyfish-2.0.la
CLEANFILES += $(PYTHON_BUILT) $(pythonext_SCRIPTS)
PYTHONC_V_GEN = $(pythonc_v_GEN_$(V))
pythonc_v_GEN_ = $(pythonc_v_GEN_$(AM_DEFAULT_VERBOSITY))
pythonc_v_GEN_0 = @echo " PYTHONC " $@;
%/__init__.pyc: %/jellyfish.py
%/__init__.pyc: %/dna_jellyfish.py
$(PYTHONC_V_GEN)$(PYTHON) -c 'import py_compile, sys; py_compile.compile(sys.argv[1], sys.argv[2])' $< $@
swig/python/jellyfish.py: swig/python/swig_wrap.cpp
swig/python/dna_jellyfish.py: swig/python/swig_wrap.cpp
EXTRA_DIST += $(PYTHON_BUILT)
endif

Expand Down
17 changes: 16 additions & 1 deletion swig/jellyfish.i
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
#ifdef SWIGPYTHON
// Default Python loading code does not seem to work. Use our own.
%define MODULEIMPORT
"
import os
if os.path.basename(__file__) == \"__init__.pyc\" or os.path.basename(__file__) == \"__init__.py\":
import dna_jellyfish.$module
else:
import $module
"
%enddef
%module(docstring="Jellyfish binding", moduleimport=MODULEIMPORT) dna_jellyfish
#else
%module(docstring="Jellyfish binding") jellyfish
#endif

%naturalvar; // Use const reference instead of pointers
%include "std_string.i"

%include "exception.i"
%include "std_except.i"
%include "typemaps.i"
%feature("autodoc", "2");

%{
#ifdef SWIGPYTHON
#define SWIG_FILE_WITH_INIT
#endif

#ifdef SWIGPERL
Expand Down
6 changes: 3 additions & 3 deletions swig/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
jf_ldflags = os.popen("pkg-config --libs-only-other jellyfish-2.0").read().rstrip().split()


jellyfish_module = Extension('_jellyfish',
jellyfish_module = Extension('_dna_jellyfish',
sources = ['jellyfish_wrap.cxx'],
include_dirs = jf_include,
libraries = jf_libs,
library_dirs = jf_libdir,
extra_compile_args = ["-std=c++0x"] + jf_cflags,
extra_link_args = jf_ldflags + jf_rpath,
language = "c++")
setup(name = 'jellyfish',
setup(name = 'dna_jellyfish',
version = '0.0.1',
author = 'Guillaume Marcais',
description = 'Access to jellyfish k-mer counting',
ext_modules = [jellyfish_module],
py_modules = ["jellyfish"])
py_modules = ["dna_jellyfish"])
12 changes: 7 additions & 5 deletions swig/python/test_hash_counter.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import unittest
import sys
import random
import jellyfish


import dna_jellyfish as jf

class TestHashCounter(unittest.TestCase):
def setUp(self):
jellyfish.MerDNA.k(100)
self.hash = jellyfish.HashCounter(1024, 5)
jf.MerDNA.k(100)
self.hash = jf.HashCounter(1024, 5)

def test_info(self):
self.assertEqual(100, jellyfish.MerDNA.k())
self.assertEqual(100, jf.MerDNA.k())
self.assertEqual(1024, self.hash.size())
self.assertEqual(5, self.hash.val_len())

def test_add(self):
mer = jellyfish.MerDNA()
mer = jf.MerDNA()
good = True
for i in range(1000):
mer.randomize()
Expand Down
8 changes: 5 additions & 3 deletions swig/python/test_mer_file.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import jellyfish
import unittest
import sys
import os
from collections import Counter

import dna_jellyfish as jf


class TestMerFile(unittest.TestCase):
def setUp(self):
self.mf = jellyfish.ReadMerFile(os.path.join(data, "swig_python.jf"))
self.mf = jf.ReadMerFile(os.path.join(data, "swig_python.jf"))

def test_histo(self):
histo = Counter()
Expand Down Expand Up @@ -46,7 +48,7 @@ def test_iter(self):

def test_query(self):
good = True
qf = jellyfish.QueryMerFile(os.path.join(data, "swig_python.jf"))
qf = jf.QueryMerFile(os.path.join(data, "swig_python.jf"))
for mer, count in self.mf:
good = good and count == qf[mer]
if not good: break
Expand Down
13 changes: 7 additions & 6 deletions swig/python/test_string_mers.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import unittest
import sys
import random
import jellyfish

import dna_jellyfish as jf

class TestStringMers(unittest.TestCase):
def setUp(self):
bases = "ACGTacgt"
self.str = ''.join(random.choice(bases) for _ in range(1000))
self.k = random.randint(10, 110)
jellyfish.MerDNA.k(self.k)
jf.MerDNA.k(self.k)

def test_all_mers(self):
count = 0
good = True
mers = jellyfish.string_mers(self.str)
mers = jf.string_mers(self.str)
for m in mers:
m2 = jellyfish.MerDNA(self.str[count:count+self.k])
m2 = jf.MerDNA(self.str[count:count+self.k])
good = good and m == m2
count += 1
self.assertTrue(good)
self.assertEqual(len(self.str) - self.k + 1, count)

def test_canonical_mers(self):
good = True
mers = jellyfish.string_canonicals(self.str)
mers = jf.string_canonicals(self.str)
for count, m in enumerate(mers):
m2 = jellyfish.MerDNA(self.str[count:count+self.k])
m2 = jf.MerDNA(self.str[count:count+self.k])
rm2 = m2.get_reverse_complement()
good = good and (m == m2 or m == rm2)
good = good and (not (m > m2)) and (not (m > rm2))
Expand Down

0 comments on commit f9d25be

Please sign in to comment.