-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathseqanpy.i
130 lines (111 loc) · 3.96 KB
/
seqanpy.i
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Created on: 26/01/2014
* Author: Fabio Zanini
* Contents: SWIG file for the seqanpy Python wrapper of SeqAn
*/
%module seqanpy
%{
#define SWIG_FILE_WITH_INIT
#include "seqanpy.h"
%}
/* STL types */
%include "std_string.i"
/* SEQANPY */
/* convert any Python input to string before passing down to C++ (duck typing) */
%pythonprepend align_global %{
seq1 = ''.join(seq1)
seq2 = ''.join(seq2)
%}
%pythonprepend align_overlap %{
seq1 = ''.join(seq1)
seq2 = ''.join(seq2)
%}
%pythonprepend align_ladder %{
seq1 = ''.join(seq1)
seq2 = ''.join(seq2)
%}
%pythonprepend align_local %{
seq1 = ''.join(seq1)
seq2 = ''.join(seq2)
%}
%pythonappend align_overlap %{
# The C++ function returs a variable called val
if cut_flanks:
s, ali1, ali2 = val
ali_start = len(ali2) - len(ali2.lstrip('-'))
ali_end = len(ali2.rstrip('-'))
ali1 = ali1[ali_start: ali_end]
ali2 = ali2[ali_start: ali_end]
val = (s, ali1, ali2)
%}
/* "output" string pointers */
%typemap(in, numinputs=0) std::string *aliout1(std::string temp) {
$1 = &temp;
}
%typemap(in, numinputs=0) std::string *aliout2(std::string temp) {
$1 = &temp;
}
%typemap(argout) std::string *aliout1 {
PyObject *alipy = PyString_FromString((*$1).c_str());
/* $result should be the C++ return value (score) */
PyObject *score = $result;
$result = PyTuple_New(3);
PyTuple_SetItem($result, 0, score);
PyTuple_SetItem($result, 1, alipy);
/* NOTE: all Python objects are still in use at the end,
so no need to reduce their refcount */
}
%typemap(argout) std::string *aliout2 {
PyObject *alipy = PyString_FromString((*$1).c_str());
/* $result should already be a tuple by now */
PyTuple_SetItem($result, 2, alipy);
}
/* Documentation */
%feature("autodoc", "0");
%feature("docstring") align_global
"Global alignment of two sequences.
Parameters:
seq1: string with the first seq
seq2: string with the second seq
band: make banded alignment, maximal shear between the sequences (-1 to turn off)
score_match: score for every match
score_mismatch: score for every mismatch (usually a negative number)
score_gapext: score for extending a gap (usually a negative number)
score_gapopen: score for opening a gap (usually a negative number)
";
%feature("docstring") align_overlap
"Align a subsequence onto a longer, reference one.
Parameters:
seq1: string with the reference seq
seq2: string with the subsequence (end gaps are free)
band: make banded alignment, maximal shear between the sequences (-1 to turn off)
score_match: score for every match
score_mismatch: score for every mismatch (usually a negative number)
score_gapext: score for extending a gap (usually a negative number)
score_gapopen: score for opening a gap (usually a negative number)
Note: band counts also gaps at the edges, so it must be used with care.
";
%feature("docstring") align_ladder
"Align two sequences where the second is an overlapping extension of the first.
Parameters:
seq1: string to be extended (end gaps are free)
seq2: string to use for extension (start gaps are free)
band: make banded alignment, maximal shear between the sequences (-1 to turn off)
score_match: score for every match
score_mismatch: score for every mismatch (usually a negative number)
score_gapext: score for extending a gap (usually a negative number)
score_gapopen: score for opening a gap (usually a negative number)
Note: band counts also gaps at the edges, so it must be used with care.
";
%feature("docstring") align_local
"Local alignment of two strings.
Parameters:
seq1: string with the first seq
seq2: string with the second seq
score_match: score for every match
score_mismatch: score for every mismatch (usually a negative number)
score_gapext: score for extending a gap (usually a negative number)
score_gapopen: score for opening a gap (usually a negative number)
";
/* HEADER */
%include "seqanpy.h"