2 ******************************************************************************
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)
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
)
35 for (int i
= 0; i
!= file_num
; ++i
)
37 Call_win
*call_win
= new Call_win(read_len
);
40 cerr
<< "\tERROR: Can't create Call_win object!" << endl
;
44 // add it to the vector
45 m_cw_vec
.push_back(call_win
);
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.
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
);
73 return CRE_WIN_FAILED
;
76 m_cw_vec
.push_back(call_win
);
77 return m_cw_vec
.size();
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
, \
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;
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.
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
;
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.
162 m_cw_vec
[index
]->deal_tail(consensus
, baseinfo
, genome
, mat
, para
, sfsMethod
, index
);
164 return SOAP2CNS_SUCCESS
;
169 * FUNCTION: the call back function that used to mutli_thread.
170 * PARAMETER: __Args is the parameter list.
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());
182 * FUNCTION: overload the Run function. Do the Call_winManager's soap2cns function.
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
);
202 call_winManager
.soap2cns(alignment_vec_p
, consensus
, baseinfo
, genome
, mat
, para
, index
, ali_index
, sfsMethod
);
206 void Call_winManager::setLast_start(int start_pos
)
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;