Permalink
Browse files

Removing C implementations of deprecated modules listfns, mathfns and…

… stringfns
  • Loading branch information...
1 parent dec0ef7 commit 2b025ba07f6298d7ecb242bdba28c545167b5cc3 @peterjc peterjc committed Dec 10, 2009
Showing with 14 additions and 468 deletions.
  1. +0 −161 Bio/clistfnsmodule.c
  2. +0 −140 Bio/cmathfnsmodule.c
  3. +0 −122 Bio/cstringfnsmodule.c
  4. +5 −11 Bio/listfns.py
  5. +3 −10 Bio/mathfns.py
  6. +3 −10 Bio/stringfns.py
  7. +3 −3 DEPRECATED
  8. +0 −11 setup.py
View
@@ -1,161 +0,0 @@
-/* Copyright 2000 by Jeffrey Chang. All rights reserved.
- * 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.
- *
- * clistfnsmodule.c
- * Created 3 Jun 2000
- */
-
-#include "Python.h"
-#include <math.h>
-
-
-
-
-/************************************** Exported Functions ***********/
-
-static char clistfns_count__doc__[] =
-"count(items) -> dict of counts of each item\n\
-\n\
-Count the number of times each item appears in a list of data.\n\
-\n\
-";
-
-static PyObject *clistfns_count(PyObject *self, PyObject *args)
-{
- int i;
- PyObject *items, *counts;
- PyObject *item, *count, *newcount;
- long int current;
-
- if(!PyArg_ParseTuple(args, "O", &items))
- return NULL;
- if(!PySequence_Check(items)) {
- PyErr_SetString(PyExc_TypeError, "expected sequence type");
- return NULL;
- }
-
- if(!(counts = PyDict_New()))
- return NULL;
-
- /* Go through the loop, counting how often each item appears. */
- i = 0;
- while(1) {
- if(!(item = PySequence_GetItem(items, i))) {
- PyErr_Clear(); /* clear the exception set by PySequence_GetItem */
- break; /* no more numbers */
- }
-
- if(!(count = PyDict_GetItem(counts, item))) {
- newcount = PyInt_FromLong(1); /* New item, set count to 1 */
- }
- else {
- current = PyInt_AsLong(count);
- newcount = PyInt_FromLong(current+1);
- }
-
- PyDict_SetItem(counts, item, newcount);
- Py_DECREF(newcount);
- Py_DECREF(item);
- if(PyErr_Occurred())
- return NULL;
-
- i++;
- }
-
- return counts;
-}
-
-
-static char clistfns_contents__doc__[] =
-"contents(items) -> dict of item -> percentage\n\
-\n\
-Summarize the contents of the list in terms of the percentages of each\n\
-item. For example, if an item appears 3 times in a list with 10 items,\n\
-it is in 0.3 of the list\n\
-\n\
-";
-
-static PyObject *clistfns_contents(PyObject *self, PyObject *args)
-{
- int i;
- PyObject *items, *counts, *percentages;
- PyObject *countitems, *countitem;
- PyObject *key, *count, *perc;
- long c;
- double total;
-
- if(!PyArg_ParseTuple(args, "O", &items))
- return NULL;
- if(!PySequence_Check(items)) {
- PyErr_SetString(PyExc_TypeError, "expected mapping type");
- return NULL;
- }
- if((total = PySequence_Length(items)) == -1) {
- PyErr_SetString(PyExc_ValueError, "I couldn't get length of item.");
- return NULL;
- }
-
- counts = clistfns_count(self, args);
- if(!counts || PyErr_Occurred())
- return NULL;
-
- if(!(percentages = PyDict_New())) {
- Py_DECREF(counts);
- return NULL;
- }
-
- /* Loop through every element in counts, calculating the probabilities. */
- if(!(countitems = PyMapping_Items(counts))) {
- Py_DECREF(counts);
- Py_DECREF(percentages);
- return NULL;
- }
-
- /* Go through the loop, counting how often each item appears. */
- i = 0;
- while(1) {
- if(!(countitem = PyList_GetItem(countitems, i))) {
- PyErr_Clear(); /* clear the exception set by PyList_GetItem */
- break; /* no more numbers */
- }
- key = PyTuple_GetItem(countitem, 0);
- count = PyTuple_GetItem(countitem, 1);
- c = PyInt_AsLong(count);
- perc = PyFloat_FromDouble((double)c / total);
- PyDict_SetItem(percentages, key, perc);
- Py_DECREF(perc);
- if(PyErr_Occurred()) /* PyDict_SetItem failed */
- break;
- i++;
- }
- if(PyErr_Occurred()) {
- Py_DECREF(percentages);
- percentages = NULL;
- }
- Py_DECREF(countitems);
- Py_DECREF(counts);
-
- return percentages;
-}
-
-
-/************************************** Module definition stuff ******/
-
-static PyMethodDef clistfnsMethods[] = {
- {"count", clistfns_count, METH_VARARGS, clistfns_count__doc__},
- {"contents", clistfns_contents, METH_VARARGS, clistfns_contents__doc__},
- {NULL, NULL}
-};
-
-static char clistfns__doc__[] =
-"This provides helper functions for the listfns module.\n\
-You should never import this module on its own.\n\
-\n\
-";
-
-void initclistfns(void)
-{
- (void) Py_InitModule3("clistfns", clistfnsMethods, clistfns__doc__);
-}
View
@@ -1,140 +0,0 @@
-/* Copyright 2000 by Jeffrey Chang. All rights reserved.
- * 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.
- *
- * cmathfnsmodule.c
- * Created 3 Jun 2000
- */
-
-#include "Python.h"
-#include <math.h>
-
-#include "csupport.h"
-
-
-
-/************************************** Exported Functions ***********/
-
-static char cmathfns_intd__doc__[] =
-"intd(x[, digits_after_decimal]) -> int x, rounded\n\
-\n\
-Represent a floating point number with some digits after the\n\
-decimal point as an integer. This is useful when floating point\n\
-comparisons are failing due to precision problems. e.g.\n\
-intd(5.35, 1) -> 54.\n\
-\n\
-";
-
-static PyObject *cmathfns_intd(
- PyObject *self, PyObject *args, PyObject *keywds)
-{
- PyObject *digits_after_decimal = Py_None;
- double x, digits;
- double precision;
-
- static char *kwlist[] = {"x", "digits_after_decimal", NULL};
- if(!PyArg_ParseTupleAndKeywords(args, keywds, "d|O", kwlist,
- &x, &digits_after_decimal))
- return NULL;
-
- if(digits_after_decimal == Py_None)
- digits = 0;
- else {
- digits = PyNumber_AsDouble(digits_after_decimal);
- if(PyErr_Occurred()) {
- return NULL;
- }
- }
- precision = pow(10, digits);
- if(x >= 0)
- x = (int)(x * precision + 0.5);
- else
- x = (int)(x * precision - 0.5);
- return PyFloat_FromDouble(x);
-}
-
-
-
-
-static char cmathfns_fcmp__doc__[] =
-"fcmp(x, y, precision) -> -1, 0, or 1";
-
-static PyObject *cmathfns_fcmp(
- PyObject *self, PyObject *args, PyObject *keywds)
-{
- double x, y, precision;
- int result;
-
- static char *kwlist[] = {"x", "y", "precision", NULL};
- if(!PyArg_ParseTupleAndKeywords(args, keywds, "ddd", kwlist,
- &x, &y, &precision))
- return NULL;
-
- if(fabs(x-y) < precision)
- result = 0;
- else if(x < y)
- result = -1;
- else result = 1;
- return PyInt_FromLong(result);
-}
-
-
-
-static char cmathfns_safe_log__doc__[] =
-"safe_log(n, zero=None, neg=None) -> log(n)\n\
-\n\
-Calculate the log of n. If n is 0, returns the value of zero. If n is\n\
-negative, returns the value of neg.\n\
-\n\
-";
-
-static PyObject *cmathfns_safe_log(
- PyObject *self, PyObject *args, PyObject *keywds)
-{
- PyObject *zero = Py_None,
- *neg = Py_None;
- double n;
-
- static char *kwlist[] = {"n", "zero", "neg", NULL};
-
- if(!PyArg_ParseTupleAndKeywords(args, keywds, "d|OO", kwlist,
- &n, &zero, &neg))
- return NULL;
-
- if(n < 0) {
- Py_INCREF(neg);
- return neg;
- } else if(n < 1E-100) {
- Py_INCREF(zero);
- return zero;
- }
-
- return PyFloat_FromDouble(log(n));
-}
-
-
-
-
-/************************************** Module definition stuff ******/
-
-static PyMethodDef cmathfnsMethods[] = {
- {"fcmp", (PyCFunction)cmathfns_fcmp, METH_VARARGS|METH_KEYWORDS,
- cmathfns_fcmp__doc__},
- {"intd", (PyCFunction)cmathfns_intd, METH_VARARGS|METH_KEYWORDS,
- cmathfns_intd__doc__},
- {"safe_log", (PyCFunction)cmathfns_safe_log, METH_VARARGS|METH_KEYWORDS,
- cmathfns_safe_log__doc__},
- {NULL, NULL}
-};
-
-static char cmathfns__doc__[] =
-"This provides helper functions for the mathfns module.\n\
-You should never import this module on its own.\n\
-\n\
-";
-
-void initcmathfns(void)
-{
- (void) Py_InitModule3("cmathfns", cmathfnsMethods, cmathfns__doc__);
-}
Oops, something went wrong.

0 comments on commit 2b025ba

Please sign in to comment.