...
 
Commits (13)
......@@ -9,5 +9,6 @@ pyvenv.cfg
pip-selfcheck.json
tests/__pycache__/
description_extractor.egg-info/
extractor-core/
......@@ -11,8 +11,14 @@ Extract a list of differences between two sequences.
`python setup.py install` or `pip install .`
## Testing
`pip install -r requirements` or `pip install pytest`
`py.test`
## Use
`import extractor`
`variants = extractor.describe_dna('AAATAA', 'AAAGAAA')`
`variants = extractor.describe_dna('TAACAATGGAAC', 'TAAACAATTGAA')`
......@@ -9,23 +9,23 @@
#include <vector>
static PyObject*
static PyObject const*
point_location(size_t const point)
{
return Py_BuildValue("{s:s,s:i}", "type", "point", "position", point);
} // point_location
static PyObject*
static PyObject const*
range_location(size_t const start, size_t const end)
{
PyObject* start_object = point_location(start);
PyObject const* const start_object = point_location(start);
if (start_object == NULL)
{
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for Py_BuildValue");
return NULL;
} // if
PyObject* end_object = point_location(end);
PyObject const* const end_object = point_location(end);
if (end_object == NULL)
{
Py_DECREF(start_object);
......@@ -36,24 +36,45 @@ range_location(size_t const start, size_t const end)
} // range_location
static PyObject*
static PyObject const*
insertion_dict(mutalyzer::Variant const &variant)
{
PyObject* reference_range = range_location(variant.reference_start, variant.reference_end);
if (reference_range == NULL)
if ((variant.type & mutalyzer::IDENTITY) == mutalyzer::IDENTITY)
{
PyObject const* const range = range_location(variant.transposition_start, variant.transposition_end);
if (range == NULL)
{
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for Py_BuildValue");
return NULL;
} // if
return Py_BuildValue("{s:s,s:O}", "source", "reference", "location", range);
} // if
else if ((variant.type & mutalyzer::REVERSE_COMPLEMENT) == mutalyzer::REVERSE_COMPLEMENT)
{
PyObject const* const range = range_location(variant.transposition_start, variant.transposition_end);
if (range == NULL)
{
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for Py_BuildValue");
return NULL;
} // if
return Py_BuildValue("{s:s,s:s,s:O}", "inverted", "true", "source", "reference", "location", range);
} // if
PyObject const* const range = range_location(variant.sample_start, variant.sample_end);
if (range == NULL)
{
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for Py_BuildValue");
return NULL;
} // if
return Py_BuildValue("{s:s,s:O}", "source", "observed", "location", reference_range);
return Py_BuildValue("{s:s,s:O}", "source", "observed", "location", range);
} // insertion_dict
static PyObject*
static PyObject const*
variant_dict(std::vector<mutalyzer::Variant>::const_iterator &it)
{
PyObject* sample_range = range_location(it->sample_start, it->sample_end);
if (sample_range == NULL)
PyObject const* const range = range_location(it->reference_start, it->reference_end);
if (range == NULL)
{
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for Py_BuildValue");
return NULL;
......@@ -65,23 +86,39 @@ variant_dict(std::vector<mutalyzer::Variant>::const_iterator &it)
inserted = PyList_New(0);
if (inserted == NULL)
{
Py_DECREF(sample_range);
Py_DECREF(range);
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for PyList_New");
return NULL;
} // if
PyObject const* const item = insertion_dict(*it);
if (item == NULL)
{
Py_DECREF(range);
Py_DECREF(inserted);
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for Py_BuildValue");
return NULL;
} // if
if (PyList_Append(inserted, const_cast<PyObject*>(item)) != 0)
{
Py_DECREF(range);
Py_DECREF(inserted);
Py_DECREF(item);
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for PyList_Append");
return NULL;
} // if
while ((it->type & mutalyzer::TRANSPOSITION_CLOSE) != mutalyzer::TRANSPOSITION_CLOSE)
{
PyObject* item = insertion_dict(*it);
PyObject const* const item = insertion_dict(*it);
if (item == NULL)
{
Py_DECREF(sample_range);
Py_DECREF(range);
Py_DECREF(inserted);
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for Py_BuildValue");
return NULL;
} // if
if (PyList_Append(inserted, item) != 0)
if (PyList_Append(inserted, const_cast<PyObject*>(item)) != 0)
{
Py_DECREF(sample_range);
Py_DECREF(range);
Py_DECREF(inserted);
Py_DECREF(item);
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for PyList_Append");
......@@ -92,25 +129,40 @@ variant_dict(std::vector<mutalyzer::Variant>::const_iterator &it)
} // if
else if (it->type == mutalyzer::IDENTITY)
{
return Py_BuildValue("{s:s,s:O}", "type", "equal", "location", sample_range);
return Py_BuildValue("{s:s,s:O}", "type", "equal", "location", range);
} // if
else if (it->type == mutalyzer::REVERSE_COMPLEMENT)
{
return Py_BuildValue("{s:s,s:O}", "type", "inv", "location", sample_range);
return Py_BuildValue("{s:s,s:O}", "type", "inv", "location", range);
} // if
if (inserted == NULL)
{
inserted = insertion_dict(*it);
inserted = PyList_New(0);
if (inserted == NULL)
{
Py_DECREF(sample_range);
Py_DECREF(range);
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for PyList_New");
return NULL;
} // if
PyObject const* const item = insertion_dict(*it);
if (item == NULL)
{
Py_DECREF(range);
Py_DECREF(inserted);
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for Py_BuildValue");
return NULL;
} // if
if (PyList_Append(inserted, const_cast<PyObject*>(item)) != 0)
{
Py_DECREF(range);
Py_DECREF(inserted);
Py_DECREF(item);
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for PyList_Append");
return NULL;
} // if
} // if
return Py_BuildValue("{s:s,s:O,s:[O]}", "type", "delins", "location", sample_range, "insertions", inserted);
return Py_BuildValue("{s:s,s:O,s:O}", "type", "delins", "location", range, "insertions", inserted);
} // variant_dict
......@@ -139,14 +191,14 @@ extractor_describe_dna(PyObject*, PyObject* args)
for (std::vector<mutalyzer::Variant>::const_iterator it = variants.begin(); it != variants.end(); ++it)
{
PyObject* item = variant_dict(it);
PyObject const* const item = variant_dict(it);
if (item == NULL)
{
Py_DECREF(result);
PyErr_SetString(PyExc_MemoryError, "Could not allocate memory for Py_BuildValue");
return NULL;
} // if
if (PyList_Append(result, item) != 0)
if (PyList_Append(result, const_cast<PyObject*>(item)) != 0)
{
Py_DECREF(item);
Py_DECREF(result);
......@@ -162,9 +214,9 @@ static PyMethodDef ExtractorMethods[] =
{
{"describe_dna", extractor_describe_dna, METH_VARARGS,
"Give an allele description of the change from {reference} to {observed}.\n"
" :arg ascii reference: Reference sequence.\n"
" :arg ascii observed: Observed sequence.\n"
" :returns list({}): A list of dictionaries representing the obsereved allele in terms of the reference sequence."
" :arg ascii reference: Reference sequence over the alphabet {A, C, G, T, U}.\n"
" :arg ascii observed: Observed sequence over the alphabet {A, C, G, T, U}.\n"
" :returns list({}): A list of dictionaries representing the obsereved allele in terms of the reference sequence."
},
{NULL, NULL, 0, NULL} // sentinel
......
......@@ -15,11 +15,12 @@ if not RELEASE:
class git_clone_external(build_ext):
def run(self):
subprocess.check_call(['rm', '-rf', 'extractor-core'])
subprocess.check_call(['git', 'clone', 'git@github.com:mutalyzer/extractor-core.git'])
subprocess.check_call(['git', 'clone', 'https://github.com/mutalyzer/extractor-core.git'])
build_ext.run(self)
extractor = Extension('extractor', sources = ['extractor-module.cc',
extractor = Extension('extractor', sources = ['extractor-wrapper.cc',
'extractor-core/src/extractor.cc'])
setup(name = 'description-extractor',
version = VERSION,
cmdclass = {'build_ext': git_clone_external},
......
This diff is collapsed.