forked from PASSIONLab/BELLA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myMarkov.h
64 lines (55 loc) · 1.5 KB
/
myMarkov.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef MARKOV_H
#define MARKOV_H
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <istream>
#include <string>
#include <stdlib.h>
#include <utility>
#include <Python.h>
#include <cstring>
#include <string.h>
#include <cassert>
#include <ios>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include "mtspgemm2017/common.h"
int myMarkovFunc(BELLApars& b_pars)
{
// https://stackoverflow.com/questions/3286448/calling-a-python-method-from-c-c-and-extracting-its-return-value/24687260
// set PYTHONPATH to working directory
setenv("PYTHONPATH",".",1);
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *presult;
// init
Py_Initialize();
// build the name object
pName = PyString_FromString((char*)"myMarkov");
// load the module object
pModule = PyImport_Import(pName);
// pDict is a borrowed reference
pDict = PyModule_GetDict(pModule);
// pFunc is also a borrowed reference
pFunc = PyDict_GetItemString(pDict, (char*)"myOverlap");
if(PyCallable_Check(pFunc))
{
double myProb = 1-b_pars.errorRate;
pValue = Py_BuildValue("(di)", myProb, b_pars.kmerSize);
PyErr_Print();
presult = PyObject_CallObject(pFunc, pValue);
PyErr_Print();
} else
{
PyErr_Print();
}
int result = PyInt_AsLong(presult);
Py_DECREF(pValue);
// clean up
Py_DECREF(pModule);
Py_DECREF(pName);
Py_Finalize();
return result;
}
#endif //MARKOV_H