~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to pyOpenMS/addons/IDRipper.pyx

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
    def rip(self, dict ripped, list proteins, list peptides):
 
4
 
 
5
  
 
6
        # Input types:
 
7
        # ripped   :  libcpp_map[String, libcpp_pair[ libcpp_vector[ProteinIdentification], libcpp_vector[PeptideIdentification]]]
 
8
        # proteins :  libcpp_vector[ProteinIdentification] 
 
9
        # peptides :  libcpp_vector[PeptideIdentification] 
 
10
 
 
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()))
 
16
 
 
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()))
 
22
 
 
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'
 
30
 
 
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():
 
39
 
 
40
            c_protein_vec_inner.clear()
 
41
            c_peptide_vec_inner.clear()
 
42
 
 
43
            prot_vec = v[0]
 
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()))
 
47
 
 
48
            pep_vec = v[1]
 
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()))
 
52
 
 
53
            aPair = new libcpp_pair[ libcpp_vector[_ProteinIdentification], libcpp_vector[_PeptideIdentification]]( deref(c_protein_vec_inner), deref(c_peptide_vec_inner) )
 
54
 
 
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)
 
58
 
 
59
            del aPair
 
60
 
 
61
        #
 
62
        ## Make the function call
 
63
        # 
 
64
        self.inst.get().rip(c_ripped, deref(c_protein_vec), deref(c_peptide_vec))
 
65
 
 
66
        #
 
67
        ## Get the data back from C++
 
68
        #
 
69
        replace = dict()
 
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
 
83
 
 
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)
 
90
                inc(it_prot)
 
91
 
 
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)
 
98
                inc(it_pep)
 
99
 
 
100
            replace[ <libcpp_string>deref(it_ripped).first ]  = [ replace_inner_protein, replace_inner_peptide] 
 
101
            inc(it_ripped)
 
102
        ripped.clear()
 
103
        ripped.update(replace)
 
104
 
 
105
        del c_peptide_vec
 
106
        del c_protein_vec
 
107
        del c_protein_vec_inner
 
108
        del c_peptide_vec_inner
 
109
 
 
110