limit fstBC to 30bp in Python3 ver.
[GalaxyCodeBases.git] / BGI / SOAPsnp / Call_winManager.cpp
blobbc3ceebc4b190c841e8f4fd8b1603f484f49d5fa
1 /*
2 ******************************************************************************
3 *Copyright 2010
4 * BGI-SHENZHEN
5 *All Rights Reserved
6 *ATHUOR : Bill Tang
7 *CREATE DATE : 2010-8-10
8 *CLASS NAME: Call_winManager
9 *FUNCTION : a class that can control Call_win vector.
10 *FILE NAME : Call_winManager.cpp
11 *UPDATE DATE : 2010-9-15
12 *UPDATE BY : Bill Tang
13 *******************************************************************************
17 #include "Call_winManager.h"
20 Call_winManager::Call_winManager(void)
22 m_cw_vec.clear();
26 /**
27 * DATE: 2010-10-12
28 * FUNCTION: a constructor that can initialize the m_cw_vec vector.
29 * PARAMETER: read_len: the longest read's length. file_name
30 * RETURN: the flag of addCallwin result.
32 Call_winManager::Call_winManager(ubit64_t read_len, int file_num, Genome* genome)
34 m_cw_vec.clear();
35 for (int i = 0; i != file_num; ++i)
37 Call_win *call_win = new Call_win(read_len);
38 if (call_win == NULL)
40 cerr << "\tERROR: Can't create Call_win object!" << endl;
41 exit(0);
44 // add it to the vector
45 m_cw_vec.push_back(call_win);
46 // initializion.
47 call_win->initialize(0);
48 call_win->current_chr = genome->chromosomes.end();
52 Call_winManager::~Call_winManager(void)
54 for (int i = 0; i < m_cw_vec.size(); ++i)
56 // release the memory.
57 delete m_cw_vec[i];
62 /**
63 * DATE: 2010-8-9
64 * FUNCTION: add a Call_win object to the Call_win vector.
65 * PARAMETER: read_len: the longest read's length.
66 * RETURN: the flag of addCallwin result.
68 int Call_winManager::addCallwin(ubit64_t read_len)
70 Call_win *call_win = new Call_win(read_len);
71 if (call_win == NULL)
73 return CRE_WIN_FAILED;
76 m_cw_vec.push_back(call_win);
77 return m_cw_vec.size();
81 /**
82 * DATE: 2010-8-9
83 * FUNCTION: soap to consensus.
84 * PARAMETER: alignment_vec: alignments to be processed. consensus: the out file handle.
85 * baseinfo: the out file handle. para: the Parameter pointer.
86 * genome: pointer of object that contian reference information.
87 * index: index of the Call_win which to be processed.
88 * ali_index: the index of m_ali_vec that can be processed in the beginning of the 'soap2cns'
89 * sfsMethod: a SfsMethod object, use to sfs.
90 * RETURN: CRE_WIN_FAILED when create Call_win failed. INDEX_EXCEED when index exceed
91 * SOAP2CNS_SUCCESS when successful.
92 * UPDATE: 2010-10-12, reduce the addCallwin part.
93 * UPDATE : 2010-11-22 process the win before new reads outsid the window
95 int Call_winManager::soap2cns(vector<Soap_format>& alignment_vec, \
96 gzoutstream * consensus,\
97 my_ofstream& baseinfo, \
98 Genome* genome, \
99 Prob_matrix* mat,\
100 Parameter* para, \
101 int index, \
102 int ali_index, \
103 SfsMethod &sfsMethod)
105 /* if (index == m_cw_vec.size())
107 // create a new Call_win object.
108 if (addCallwin(para->read_length) != (index + 1))
110 return CRE_WIN_FAILED;
113 // initialize.
114 m_cw_vec[index]->initialize(0);
115 m_cw_vec[index]->current_chr = genome->chromosomes.end();
119 if (index > m_cw_vec.size())
121 // index is over flow.
122 return INDEX_EXCEED;
125 //process the win before new reads outsid the window
126 for (int i = ali_index; i < alignment_vec.size(); ++i)
128 m_cw_vec[index]->deal_read(alignment_vec[i], consensus, baseinfo, genome, mat, para, sfsMethod, index);
130 // add by guyue 2010-11-25
131 if (!m_cw_vec[index]->done_pro_win && m_cw_vec[index]->last_start > 999)
133 m_cw_vec[index]->recycled = false;
134 m_cw_vec[index]->pro_win(consensus, baseinfo, genome, mat, para, sfsMethod, index);
136 m_cw_vec[index]->done_pro_win = false;
137 // clear up the alignments.
138 alignment_vec.clear();
139 return SOAP2CNS_SUCCESS;
144 * DATE: 2010-8-9
145 * FUNCTION: deal the tail of sample.
146 * PARAMETER: consensus: the out file handle.
147 * baseinfo: the out file handle. para: the Parameter pointer.
148 * genome: pointer of object that contian reference information.
149 * index: index of the Call_win which to be processed.
150 * sfsMethod: a SfsMethod object, use to sfs.
151 * RETURN: INDEX_EXCEED when index exceed
152 * SOAP2CNS_SUCCESS when successful.
154 int Call_winManager::dealTail(gzoutstream * consensus, my_ofstream& baseinfo, Genome* genome, Prob_matrix* mat, Parameter* para, int index, SfsMethod &sfsMethod)
156 if (index >= m_cw_vec.size())
158 // index is over flow.
159 return INDEX_EXCEED;
162 m_cw_vec[index]->deal_tail(consensus, baseinfo, genome, mat, para, sfsMethod, index);
164 return SOAP2CNS_SUCCESS;
168 * DATE: 2010-10-14
169 * FUNCTION: the call back function that used to mutli_thread.
170 * PARAMETER: __Args is the parameter list.
171 * RETURN:
173 //void* _call_winManager_soap2cns_norm(void * __Args)
175 // _call_win_args * _args=(_call_win_args*) __Args;
176 // _args->call_winManager->soap2cns(_args->readwin->getReadwin(), *(_args->consensus),*(_args->baseinfo),_args->genome,_args->mat, _args->para, _args->index, _args->readwin->getSoap2cnsIdx());
181 * DATE: 2010-10-13
182 * FUNCTION: overload the Run function. Do the Call_winManager's soap2cns function.
183 * PARAMETER:
184 * RETURN:
186 int Call_win_Task::Run()
188 CALL_WIN_ARGS *call_win_args = (CALL_WIN_ARGS*)this->m_ptrData;
189 // set all the parameters.
190 Call_winManager & call_winManager = *(call_win_args->call_winManager_p);
191 vector<Soap_format> & alignment_vec_p = *(call_win_args->alignment_vec_p);
192 gzoutstream * consensus = call_win_args->consensus_p;
193 my_ofstream & baseinfo = *(call_win_args->baseinfo_p);
194 Genome * genome = call_win_args->genome;
195 Prob_matrix * mat = call_win_args->mat;
196 Parameter * para = call_win_args->para;
197 int index = call_win_args->index;
198 int ali_index = call_win_args->ali_index;
199 SfsMethod & sfsMethod = *(call_win_args->sfsMethod_p);
201 // do the soap2cns.
202 call_winManager.soap2cns(alignment_vec_p, consensus, baseinfo, genome, mat, para, index, ali_index, sfsMethod);
203 return 1;
206 void Call_winManager::setLast_start(int start_pos)
208 if (start_pos <= 0)
210 return;
212 for (int i = 0; i < m_cw_vec.size(); ++i)
214 m_cw_vec[i]->last_start = start_pos;
215 m_cw_vec[i]->m_is_set_ls = true;