Permalink
Browse files

Replacing Bio.Restriction.DNAUtils C code with pure python and deprec…

…ating it
  • Loading branch information...
1 parent ac201d9 commit d52e8d473cbd55cc62e49f07f102a5eb1a59b3d2 @peterjc peterjc committed Dec 9, 2009
Showing with 35 additions and 134 deletions.
  1. +0 −134 Bio/Restriction/DNAUtils.c
  2. +28 −0 Bio/Restriction/DNAUtils.py
  3. +7 −0 DEPRECATED
View
134 Bio/Restriction/DNAUtils.c
@@ -1,134 +0,0 @@
-/* DNA IUPAC ambiguous "ACBDGHKMNSRTWVYacbdghkmnsrtwvy"
-// DNA IUPAC ambiguous complement "TGVHCDMKNSYAWBRtgvhcdmknsyawbr"
-
-DNA_complement from PyString_translate (stringobject.c Python2.3.4)
-*/
-#include "Python.h"
-
-static PyObject *
-DNA_checkbases(PyObject *bogus, PyStringObject *string)
-{
- register char *input, *output;
- register int i;
- register char c;
- register const char *table =
- " zz z z "
- " zzzzzzzzzz ABCD GH K MN RST VW Y z"
- " ABCD GH K MN RST VW Y "
- " "
- " "
- " ";
- PyObject *input_obj = (PyObject *)string, *result;
- int len;
- i = PyString_Size(input_obj);
- input = PyString_AsString(input_obj);
- result = PyString_FromStringAndSize((char *)NULL, i+1);
- if (result == NULL)
- return NULL;
-
- output = PyString_AsString(result);
- output[0] = ' ';
- len = 1;
- for (;--i >= 0;) {
- c = table[Py_CHARMASK(*input++)];
- if (c == 'z') continue;
- else if (c == ' ') {
- PyErr_SetString(PyExc_TypeError, "All bases must IUPAC letters");
- return NULL;
- }
- output[len] = c;
- len++;
- }
- _PyString_Resize(&result, len);
- return result;
-}
-
-static PyObject *
-DNA_complement(PyObject *bogus, PyStringObject *string)
-{
- register char *input, *output;
- register int i;
- register const char *table =
- " "
- " TVGHEFCDIJMLKNOPQYSAUBWXRZ "
- " tvghefcdijmlknopqysaubwxrz "
- " "
- " "
- " ";
- PyObject *input_obj = (PyObject *)string, *result;
-
- i = PyString_Size(input_obj);
- result = PyString_FromStringAndSize((char *)NULL, i);
- if (result == NULL)
- return NULL;
- output = PyString_AsString(result);
- input = PyString_AsString(input_obj);
-
- for (;--i >= 0;) *output++ = table[Py_CHARMASK(*input++)];
-
- return result;
-}
-
-static PyObject *
-DNA_rev_compl(PyObject *bogus, PyStringObject *string)
-{
- register char *input, *output;
- register int i;
- register const char *table =
- " "
- " TVGHEFCDIJMLKNOPQYSAUBWXRZ "
- " tvghefcdijmlknopqysaubwxrz "
- " "
- " "
- " ";
- PyObject *input_obj = (PyObject *)string, *result;
-
- i = PyString_Size(input_obj);
- result = PyString_FromStringAndSize((char *)NULL, i);
- if (result == NULL)
- return NULL;
- output = PyString_AsString(result);
- input = PyString_AsString(input_obj);
-
- for (;--i >= 0;) output[i] = table[Py_CHARMASK(*input++)];
- return result;
-}
-
-
-PyDoc_STRVAR(DNA_complement_doc,
-"complement(string) -> string.\n\
-\n\
-the new string is the complementary strand of the \n\
-input. string must be a IUPAC ambiguous alphabet.\n");
-
-PyDoc_STRVAR(DNA_rev_compl_doc,
-"antiparallel(string) -> string.\n\
-\n\
-the new string is the reverse complementary strand \n\
-(antiparallel) of the input.\n\
- string must be a IUPAC ambiguous alphabet.\n");
-
- PyDoc_STRVAR(DNA_checkbases_doc,
-"check_bases(string) -> string.\n\
-\n\
-check that the bases in string are in the IUPAC ambiguous alphabet.\n\
-Remove digits and white space present in string.\n");
-
-static PyMethodDef DNAUtils_functions[] = {
- {"check_bases", (PyCFunction)DNA_checkbases, METH_O, DNA_checkbases_doc},
- {"complement", (PyCFunction)DNA_complement, METH_O, DNA_complement_doc},
- {"antiparallel", (PyCFunction)DNA_rev_compl, METH_O, DNA_rev_compl_doc},
- {NULL, NULL} /* sentinel */
-};
-
-PyMODINIT_FUNC
-initDNAUtils(void)
-{
- PyObject *m;
-
- m = Py_InitModule3("DNAUtils",
- DNAUtils_functions,
- "some functions for use with DNA object.");
- if (m == NULL)
- return;
-}
View
28 Bio/Restriction/DNAUtils.py
@@ -0,0 +1,28 @@
+# This code is part of the Biopython distribution and governed by its
+# license. Please see the LICENSE file that should have been included
+# as part of this package.
+
+"""DNA utilities for Bio.Restriction (DEPRECATED).
+
+DNAUtils was written in C and therefore would not be available on Jython etc.
+It offered three string based functions:
+ - complement, duplicating the functionality of the Seq object
+ - antiparallel, duplicating the functionality of the Seq object and
+ the reverse_complement function in Bio.Seq
+ - check_bases, a very odd validation routine unlikely to be of general use.
+"""
+
+import warnings
+warnings.warn("Bio.Restriction.DNAUtils is deprecated, and will be "
+ "removed in a future release of Biopython.")
+del warnings
+
+#expose these existing functions mimicking the old DNAUtils names:
+from Bio.Seq import reverse_complement as antiparallel
+
+#quick and dirty complement function, maybe we should add one to Bio.Seq?
+def complement(seq_string) :
+ return antiparallel(seq_string)[::-1]
+
+#expose this re-implementation of the old C code function check_bases:
+from Bio.Restriction.Restriction import _check_bases as check_bases
View
7 DEPRECATED
@@ -7,6 +7,13 @@ Python 2.3
No longer supported as of Release 1.51, having triggered a warning with
Release 1.50, with a mention in the release notes for Release 1.49.
+Bio.Restriction.DNAUtils and check_bases
+========================================
+This module (originally in C) offered complement and antiparallel functions
+(duplicating functionality in Bio.Seq) and a rather odd function called
+check_bases (also available as Bio.Restriction.Restriction.check_bases).
+Deprecated in Release 1.53.
+
Bio.Blast.NCBIStandalone.blastall, blastpgp and rpsblast
========================================================
These command line tools calling functions were declared obsolete in Release

0 comments on commit d52e8d4

Please sign in to comment.