You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

orcamodule.cpp 1.7KB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <Python.h>
  5. #include "orca/orca.h"
  6. static PyObject *
  7. orca_motifs(PyObject *self, PyObject *args)
  8. {
  9. const char *orbit_type;
  10. int graphlet_size;
  11. const char *input_filename;
  12. const char *output_filename;
  13. int sts;
  14. if (!PyArg_ParseTuple(args, "siss", &orbit_type, &graphlet_size, &input_filename, &output_filename))
  15. return NULL;
  16. sts = system(orbit_type);
  17. motif_counts(orbit_type, graphlet_size, input_filename, output_filename);
  18. return PyLong_FromLong(sts);
  19. }
  20. static PyMethodDef OrcaMethods[] = {
  21. {"motifs", orca_motifs, METH_VARARGS,
  22. "Compute motif counts."},
  23. };
  24. static struct PyModuleDef orcamodule = {
  25. PyModuleDef_HEAD_INIT,
  26. "orca", /* name of module */
  27. NULL, /* module documentation, may be NULL */
  28. -1, /* size of per-interpreter state of the module,
  29. or -1 if the module keeps state in global variables. */
  30. OrcaMethods
  31. };
  32. PyMODINIT_FUNC
  33. PyInit_orca(void)
  34. {
  35. return PyModule_Create(&orcamodule);
  36. }
  37. int main(int argc, char *argv[]) {
  38. wchar_t *program = Py_DecodeLocale(argv[0], NULL);
  39. if (program == NULL) {
  40. fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
  41. exit(1);
  42. }
  43. /* Add a built-in module, before Py_Initialize */
  44. PyImport_AppendInittab("orca", PyInit_orca);
  45. /* Pass argv[0] to the Python interpreter */
  46. Py_SetProgramName(program);
  47. /* Initialize the Python interpreter. Required. */
  48. Py_Initialize();
  49. /* Optionally import the module; alternatively,
  50. import can be deferred until the embedded script
  51. imports it. */
  52. PyImport_ImportModule("orca");
  53. PyMem_RawFree(program);
  54. }