• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DEploid-dev / DEploid / 062add94-a5b5-4fd4-a562-e213ecc8da7c

20 Jan 2025 05:00PM UTC coverage: 86.049% (-0.1%) from 86.156%
062add94-a5b5-4fd4-a562-e213ecc8da7c

push

circleci

web-flow
Merge pull request #377 from DEploid-dev/shajoezhu-patch-1

Update config.yml

5545 of 6444 relevant lines covered (86.05%)

5298085.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/src/export/dEploidIOExportPosteriorProb.cpp
1
/*
2
 * dEploid is used for deconvoluting Plasmodium falciparum genome from
3
 * mix-infected patient sample.
4
 *
5
 * Copyright (C) 2016-2017 University of Oxford
6
 *
7
 * Author: Sha (Joe) Zhu
8
 *
9
 * This file is part of dEploid.
10
 *
11
 * dEploid is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25

26
#include "dEploidIO.hpp"
27
#include "updateHap.hpp"
28
#include "mcmc.hpp"
29

30
void McmcMachinery::writeLastFwdProb(bool useIBD) {
56✔
31
    if (this->dEploidIO_ ->doExportPostProb() != true) {
56✔
32
        return;
33
    }
34

35
    for (size_t tmpk = 0; tmpk < this->kStrain_; tmpk++) {
×
36
        if (this->dEploidIO_->doAllowInbreeding() == true) {
×
37
            this->updateReferencePanel(this->panel_->truePanelSize()+kStrain_-1,
×
38
                tmpk);
39
        }
40

41
        for (size_t chromi = 0 ;
×
42
            chromi < this->dEploidIO_->indexOfChromStarts_.size(); chromi++) {
×
43
            size_t start = this->dEploidIO_->indexOfChromStarts_[chromi];
×
44
            size_t length = this->dEploidIO_->position_[chromi].size();
45

46
            UpdateSingleHap updatingSingle(this->dEploidIO_->refCount_,
×
47
                                  this->dEploidIO_->altCount_,
×
48
                                  this->dEploidIO_->plaf_,
×
49
                                  this->currentExpectedWsaf_,
×
50
                                  this->currentProp_,
×
51
                                  this->currentHap_,
×
52
                                  this->hapRg_,
53
                                  start, length,
54
                                  this->panel_,
55
                                  this->dEploidIO_->missCopyProb_.getValue(),
56
                                  this->dEploidIO_->scalingFactor(),
57
                                  tmpk);
×
58
            if (this->dEploidIO_->doAllowInbreeding() == true) {
×
59
                updatingSingle.setPanelSize(
60
                    this->panel_->inbreedingPanelSize());
×
61
            }
62

63
            updatingSingle.core(this->dEploidIO_->refCount_,
×
64
                                this->dEploidIO_->altCount_,
×
65
                                this->dEploidIO_->plaf_,
×
66
                                this->currentExpectedWsaf_,
67
                                this->currentProp_,
68
                                this->currentHap_);
69
            this->dEploidIO_->writeLastSingleFwdProb(
×
70
                updatingSingle.fwdProbs_, chromi, tmpk, useIBD);
71
        }
×
72
        // UpdatePairHap updating( this->dEploidIO_->refCount_,
73
                                // this->dEploidIO_->altCount_,
74
                                // this->dEploidIO_->plaf_,
75
                                // this->currentExpectedWsaf_,
76
                                // this->currentProp_,
77
                                // this->currentHap_, this->hapRg_,
78
                                // start, length,
79
                                // this->panel_,
80
                                // this->dEploidIO_->missCopyProb_,
81
                                // this->dEploidIO_->forbidCopyFromSame(),
82
                                // (size_t)0,
83
                                // (size_t)1);
84
        // updating.core(this->dEploidIO_->refCount_,
85
        // this->dEploidIO_->altCount_, this->dEploidIO_->plaf_,
86
        // this->currentExpectedWsaf_, this->currentProp_, this->currentHap_);
87
        // this->dEploidIO_->writeLastPairFwdProb( updating, chromi );
88
    }
89
}
90

91

92
void DEploidIO::writeLastSingleFwdProb(
70✔
93
    const vector < vector <double> >& probabilities,
94
    size_t chromIndex, size_t strainIndex, bool useIBD) {
95
    if (probabilities.size() == 0) {
70✔
96
        return;
×
97
    }
98

99
    size_t panelSize = probabilities[0].size();
100

101
    string strExportFwdProb = ((useIBD == true) ?
102
        strIbdExportSingleFwdProbPrefix :
103
        strExportSingleFwdProbPrefix) + to_string(strainIndex);
70✔
104
    ofstreamExportFwdProb.open(strExportFwdProb.c_str(),
70✔
105
        ios::out | ios::app | ios::binary);
106

107
    if (chromIndex == 0) {  // Print header
70✔
108
        ofstreamExportFwdProb << "CHROM" << "\t" << "POS" << "\t";
10✔
109
        for (size_t ii = 0; ii < probabilities[0].size(); ii++) {
45✔
110
            if (this->doAllowInbreeding() == true) {
40✔
111
                if (ii <= (panelSize - this->kStrain_.getValue())) {
40✔
112
                    ofstreamExportFwdProb << "P" << (ii+1);
20✔
113
                } else {
114
                    ofstreamExportFwdProb <<
115
                        "I" << (ii)-(panelSize - this->kStrain_.getValue());
20✔
116
                }
117
            } else {
118
                ofstreamExportFwdProb << (ii+1);
×
119
            }
120
            ofstreamExportFwdProb << ((ii < (panelSize-1)) ? "\t" : "\n");
45✔
121
        }
122
    }
123

124
    size_t siteIndex = 0;
125
    for (size_t posI = 0; posI < position_[chromIndex].size(); posI++) {
3,040✔
126
        ofstreamExportFwdProb << chrom_[chromIndex] << "\t"
2,970✔
127
                              << static_cast<int>(position_[chromIndex][posI])
128
                              << "\t";
2,970✔
129
        for (size_t ii = 0; ii < probabilities[siteIndex].size(); ii++) {
26,730✔
130
            ofstreamExportFwdProb << probabilities[siteIndex][ii];
23,760✔
131
            ofstreamExportFwdProb <<
132
                ((ii < (probabilities[siteIndex].size()-1)) ? "\t" : "\n");
26,730✔
133
        }
134
        siteIndex++;
2,970✔
135
    }
136

137
    ofstreamExportFwdProb.close();
70✔
138
}
139

140

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc