3
def rip(self, dict ripped, list proteins, list peptides):
7
# ripped : libcpp_map[String, libcpp_pair[ libcpp_vector[ProteinIdentification], libcpp_vector[PeptideIdentification]]]
8
# proteins : libcpp_vector[ProteinIdentification]
9
# peptides : libcpp_vector[PeptideIdentification]
11
assert isinstance(proteins, list) and all(isinstance(li, ProteinIdentification) for li in proteins), 'arg proteins wrong type'
12
cdef libcpp_vector[_ProteinIdentification] * c_protein_vec = new libcpp_vector[_ProteinIdentification]()
13
cdef ProteinIdentification item1
14
for item1 in proteins:
15
c_protein_vec.push_back(deref(item1.inst.get()))
17
assert isinstance(peptides, list) and all(isinstance(li, PeptideIdentification) for li in peptides), 'arg peptides wrong type'
18
cdef libcpp_vector[_PeptideIdentification] * c_peptide_vec = new libcpp_vector[_PeptideIdentification]()
19
cdef PeptideIdentification item0
20
for item0 in peptides:
21
c_peptide_vec.push_back(deref(item0.inst.get()))
23
# dict -> pair ( list, list ) )
24
assert isinstance(ripped, dict) and all(isinstance(li, list) and len(li) == 2 and all(
25
isinstance(pair_element[0], list) and isinstance(pair_element[1], list) and
26
all(isinstance(proteinid, ProteinIdentification) for proteinid in pair_element[0]) and
27
all(isinstance(peptideid, PeptideIdentification) for peptideid in pair_element[1])
28
for pair_element in li)
29
for li in ripped), 'arg proteins wrong type'
31
cdef libcpp_map[_String, libcpp_pair[ libcpp_vector[_ProteinIdentification], libcpp_vector[_PeptideIdentification]]] c_ripped
32
# declaration for the loop
33
cdef libcpp_vector[_ProteinIdentification] * c_protein_vec_inner = new libcpp_vector[_ProteinIdentification]()
34
cdef ProteinIdentification i_item1
35
cdef libcpp_vector[_PeptideIdentification] * c_peptide_vec_inner = new libcpp_vector[_PeptideIdentification]()
36
cdef PeptideIdentification i_item0
37
cdef libcpp_pair[ libcpp_vector[_ProteinIdentification], libcpp_vector[_PeptideIdentification]] * aPair
38
for k,v in ripped.iteritems():
40
c_protein_vec_inner.clear()
41
c_peptide_vec_inner.clear()
44
assert isinstance(prot_vec, list) and all(isinstance(li, ProteinIdentification) for li in prot_vec), 'arg proteins wrong type'
45
for i_item1 in prot_vec:
46
c_protein_vec_inner.push_back(deref(i_item1.inst.get()))
49
assert isinstance(pep_vec, list) and all(isinstance(li, PeptideIdentification) for li in pep_vec), 'arg peptides wrong type'
50
for i_item0 in pep_vec:
51
c_peptide_vec_inner.push_back(deref(i_item0.inst.get()))
53
aPair = new libcpp_pair[ libcpp_vector[_ProteinIdentification], libcpp_vector[_PeptideIdentification]]( deref(c_protein_vec_inner), deref(c_peptide_vec_inner) )
55
assert isinstance(k, bytes), 'arg key in label_identifiers wrong type'
56
assert isinstance(v, float), 'arg value in label_identifiers wrong type'
57
c_ripped[ _String(<char *>k) ] = deref(aPair)
62
## Make the function call
64
self.inst.get().rip(c_ripped, deref(c_protein_vec), deref(c_peptide_vec))
67
## Get the data back from C++
70
cdef libcpp_map[_String, libcpp_pair[ libcpp_vector[_ProteinIdentification], libcpp_vector[_PeptideIdentification]]].iterator it_ripped = c_ripped.begin()
71
cdef libcpp_pair[ libcpp_vector[_ProteinIdentification], libcpp_vector[_PeptideIdentification]] anotherPair
72
cdef libcpp_vector[_ProteinIdentification] another_c_protein_vec_inner
73
cdef libcpp_vector[_PeptideIdentification] another_c_peptide_vec_inner
74
cdef libcpp_vector[_ProteinIdentification].iterator it_prot
75
cdef libcpp_vector[_PeptideIdentification].iterator it_pep
76
cdef ProteinIdentification item_py_result_prot
77
cdef PeptideIdentification item_py_result_pep
78
while it_ripped != c_ripped.end():
79
# get the pair and the two vectors
80
anotherPair = deref(it_ripped).second
81
another_c_protein_vec_inner = anotherPair.first
82
another_c_peptide_vec_inner = anotherPair.second
84
replace_inner_protein = []
85
it_prot = another_c_protein_vec_inner.begin()
86
while it_prot != another_c_protein_vec_inner.end():
87
item_py_result_prot = ProteinIdentification.__new__(ProteinIdentification)
88
item_py_result_prot.inst = shared_ptr[_ProteinIdentification](new _ProteinIdentification(deref(it_prot)))
89
replace_inner_protein.append(item_py_result_prot)
92
replace_inner_peptide = []
93
it_pep = another_c_peptide_vec_inner.begin()
94
while it_pep != another_c_peptide_vec_inner.end():
95
item_py_result_pep = PeptideIdentification.__new__(PeptideIdentification)
96
item_py_result_pep.inst = shared_ptr[_PeptideIdentification](new _PeptideIdentification(deref(it_pep)))
97
replace_inner_peptide.append(item_py_result_pep)
100
replace[ <libcpp_string>deref(it_ripped).first ] = [ replace_inner_protein, replace_inner_peptide]
103
ripped.update(replace)
107
del c_protein_vec_inner
108
del c_peptide_vec_inner