Skip to content

Commit f2b44d2

Browse files
committed
multiply file support
1 parent d024c53 commit f2b44d2

File tree

4 files changed

+60
-48
lines changed

4 files changed

+60
-48
lines changed

phaser.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ Phaser::Phaser(const std::string &fnvcf, const std::string &fnout, std::vector<s
2121
frbed = new BEDReader(fnbed.data());
2222
}
2323
}
24-
for (const auto& item : fnfrags) {
25-
frfrags.push_back(new FragmentReader(item.data()));
26-
}
2724
frvcf = new VCFReader(fnvcf.data());
2825
fwvcf = new VCFWriter(frvcf->header, fnout.data());
2926
// frfrag = new FragmentReader(fnfrag.data());

spectral.cpp

+53-38
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,6 @@ void Spectral::reset()
128128
for (auto item : frs) {
129129
item->set_window_info(start_variant_idx, end_variant_idx_overlap, end_variant_idx_intended);
130130
}
131-
for (auto item : frs) {
132-
item->set_window_info(start_variant_idx, end_variant_idx_overlap, end_variant_idx_intended);
133-
}
134131
// fr->set_window_info(start_variant_idx, end_variant_idx_overlap, end_variant_idx_intended);
135132
this->variant_graph.reset(variant_count);
136133
this->raw_graph = new double[n * n];
@@ -142,19 +139,27 @@ void Spectral::reset()
142139
this->raw_count[i] = 0;
143140
}
144141
this->frag_buffer.clear();
142+
// read graph
143+
ViewMap weighted_graph(raw_graph, n, n);
144+
CViewMap count_graph(raw_count, n, n);
145145
for (int i = 0; i < OPERATIONS.size(); i++) {
146146
auto item = OPERATIONS[i];
147147
if (item == MODE_10X)
148-
read_fragment_10x(i);
148+
read_fragment_10x(i,weighted_graph,count_graph);
149149
else if (item == MODE_HIC)
150-
read_fragment_hic(i);
150+
read_fragment_hic(i,weighted_graph,count_graph);
151151
else if (item == MODE_PE)
152-
read_fragment(i);
152+
read_fragment(i,weighted_graph,count_graph);
153153
else if (item == MODE_NANOPORE)
154-
read_fragment_nanopore(i);
154+
read_fragment_nanopore(i,weighted_graph,count_graph);
155155
else if (item == MODE_PACBIO)
156-
read_fragment_pacbio(i);
156+
read_fragment_pacbio(i,weighted_graph,count_graph);
157+
}
158+
// cal prob graph
159+
if (HAS_TENX){
160+
add_snp_edge_barcode(weighted_graph, count_graph);
157161
}
162+
cal_prob_matrix(weighted_graph, count_graph, nullptr, nullptr, nullptr);
158163
}
159164

160165
GMatrix Spectral::slice_submat(std::set<uint> &variants_mat, GMatrix &adj_mat)
@@ -212,23 +217,23 @@ CMatrix Spectral::slice_submat(std::set<uint> &variants_mat, bool t)
212217
}
213218

214219
// read fragment matrix
215-
void Spectral::read_fragment(int frIdx)
220+
void Spectral::read_fragment(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph)
216221
{
217222
auto fr = frs[frIdx];
218223
// this->frag_buffer.clear();
219224
Fragment fragment;
220-
ViewMap weighed_graph(raw_graph, n, n);
221-
CViewMap count_graph(raw_count, n, n);
225+
// ViewMap weighed_graph(raw_graph, n, n);
226+
// CViewMap count_graph(raw_count, n, n);
222227
while (fr->get_next_pe(fragment))
223228
{
224-
add_snp_edge(fragment, weighed_graph, count_graph);
229+
add_snp_edge(fragment, weighted_graph, count_graph);
225230
this->frag_buffer.push_back(fragment);
226231
fragment.reset();
227232
}
228-
cal_prob_matrix(weighed_graph, count_graph, nullptr, nullptr, nullptr);
233+
// cal_prob_matrix(weighted_graph, count_graph, nullptr, nullptr, nullptr);
229234
}
230235

231-
void Spectral::read_fragment_10x(int frIdx)
236+
void Spectral::read_fragment_10x(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph)
232237
{
233238
auto fr = frs[frIdx];
234239
this->region_frag_stats->clear();
@@ -238,8 +243,8 @@ void Spectral::read_fragment_10x(int frIdx)
238243
frbed->read_region_frag(this->chromo_phaser->chr_name.c_str(), start_pos, end_pos, this->region_frag_stats);
239244
//this->barcode_linker->regionFragStats = region_frag_stats;
240245
Fragment fragment;
241-
ViewMap weighed_graph(raw_graph, n, n);
242-
CViewMap count_graph(raw_count, n, n);
246+
// ViewMap weighed_graph(raw_graph, n, n);
247+
// CViewMap count_graph(raw_count, n, n);
243248

244249
while (fr->get_next_tenx(fragment))
245250
{
@@ -250,61 +255,61 @@ void Spectral::read_fragment_10x(int frIdx)
250255
//add_barcode_info(fragment, barcode_linker);
251256
fragment.reset();
252257
}
253-
add_snp_edge_barcode(weighed_graph, count_graph);
254-
cal_prob_matrix(weighed_graph, count_graph, nullptr, nullptr, nullptr);
258+
// add_snp_edge_barcode(weighted_graph, count_graph);
259+
// cal_prob_matrix(weighted_graph, count_graph, nullptr, nullptr, nullptr);
255260
}
256261

257262
//TODO: only unused HiC linker should be stored
258-
void Spectral::read_fragment_hic(int frIdx)
263+
void Spectral::read_fragment_hic(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph)
259264
{
260265
auto fr = frs[frIdx];
261266
Fragment fragment;
262267
// this->frag_buffer.clear();
263-
CViewMap count_graph(raw_count, n, n);
264-
ViewMap weighed_graph(raw_graph, n, n);
268+
// CViewMap count_graph(raw_count, n, n);
269+
// ViewMap weighed_graph(raw_graph, n, n);
265270
while (fr->get_next_hic(fragment))
266271
{
267-
add_snp_edge(fragment, weighed_graph, count_graph);
272+
add_snp_edge(fragment, weighted_graph, count_graph);
268273
this->frag_buffer.push_back(fragment);
269274
if ( fragment.snps[0].first >= phasing_window->prev_window_start)
270275
if (fragment.insertion_size >= 5000 && fragment.insertion_size <= 40000000)
271276
this->hic_linker_container.add_HiC_info(fragment);
272277
fragment.reset();
273278
}
274-
cal_prob_matrix(weighed_graph, count_graph, nullptr, nullptr, nullptr);
279+
// cal_prob_matrix(weighted_graph, count_graph, nullptr, nullptr, nullptr);
275280
}
276281

277-
void Spectral::read_fragment_nanopore(int frIdx)
282+
void Spectral::read_fragment_nanopore(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph)
278283
{
279284
auto fr = frs[frIdx];
280285
// this->frag_buffer.clear();
281286
Fragment fragment;
282-
ViewMap weighed_graph(raw_graph, n, n);
283-
CViewMap count_graph(raw_count, n, n);
287+
// ViewMap weighed_graph(raw_graph, n, n);
288+
// CViewMap count_graph(raw_count, n, n);
284289
while (fr->get_next_nanopore(fragment))
285290
{
286-
add_snp_edge(fragment, weighed_graph, count_graph);
291+
add_snp_edge(fragment, weighted_graph, count_graph);
287292
this->frag_buffer.push_back(fragment);
288293
fragment.reset();
289294
}
290295
//this->q_aver = q_sum / this->frag_buffer.size() / 6;
291-
cal_prob_matrix(weighed_graph, count_graph, nullptr, nullptr, nullptr);
296+
// cal_prob_matrix(weighted_graph, count_graph, nullptr, nullptr, nullptr);
292297
}
293298

294-
void Spectral::read_fragment_pacbio(int frIdx)
299+
void Spectral::read_fragment_pacbio(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph)
295300
{
296301
auto fr = frs[frIdx];
297302
// this->frag_buffer.clear();
298303
Fragment fragment;
299-
ViewMap weighed_graph(raw_graph, n, n);
300-
CViewMap count_graph(raw_count, n, n);
304+
// ViewMap weighed_graph(raw_graph, n, n);
305+
// CViewMap count_graph(raw_count, n, n);
301306
while (fr->get_next_pacbio(fragment))
302307
{
303-
add_snp_edge(fragment, weighed_graph, count_graph);
308+
add_snp_edge(fragment, weighted_graph, count_graph);
304309
this->frag_buffer.push_back(fragment);
305310
fragment.reset();
306311
}
307-
cal_prob_matrix(weighed_graph, count_graph, nullptr, nullptr, nullptr);
312+
// cal_prob_matrix(weighted_graph, count_graph, nullptr, nullptr, nullptr);
308313
}
309314

310315
// aid function
@@ -625,6 +630,8 @@ void Spectral::solver()
625630
//for each block (variant) in phasing window
626631
for (auto i : phasing_window->current_window_idxes)
627632
{
633+
if (i == 15)
634+
int tmp = 9;
628635
mat_idx = phasing_window->var_idx2mat_idx(i);
629636
if (met_idx.find(mat_idx) == met_idx.end())
630637
met_idx.insert(mat_idx);
@@ -667,11 +674,11 @@ void Spectral::solver()
667674
}
668675
}
669676
// TODO, if we need this
670-
if (false)
671-
{
672-
for (auto start_idx: this->phased_block_starts)
673-
barcode_aware_filter(start_idx.first);
674-
}
677+
// if (HAS_TENX)
678+
// {
679+
// for (auto start_idx: this->phased_block_starts)
680+
// barcode_aware_filter(start_idx.first);
681+
// }
675682
}
676683

677684
void Spectral::add_snp_edge_barcode_subroutine(ViewMap &sub_weighted_graph, CViewMap &sub_count_graph, VariantGraph &sub_variant_graph, std::map<uint, int> &subroutine_map, std::map<uint, uint> & subroutine_blk_start)
@@ -880,7 +887,11 @@ void Spectral::find_connected_component_dfs(const Eigen::MatrixBase<Derived> &ad
880887
std::set<uint> &nxt_vars = sub_variant_graph.graph[var_idx];
881888

882889
uint idx = phasing_window->mat_idx2var_idx(subroutine_blk_start[var_idx]);
890+
// Fixme, block_to_merge equals to starting block, this is a bug
891+
// if(idx == starting_block->block_id) return;
883892
ptr_PhasedBlock block_to_merge = phasing_window->blocks[idx];
893+
if (block_to_merge->block_id == starting_block->block_id)
894+
return;
884895
if (adj_mat(2 * prev_var_idx, 2 * var_idx) > 0)
885896
{
886897
if (block_to_merge->size() == 1)
@@ -953,7 +964,11 @@ void Spectral::find_connected_component_dfs(const Eigen::MatrixBase<Derived> &ad
953964
std::set<uint> &nxt_vars = this->variant_graph.graph[var_idx];
954965

955966
uint idx = phasing_window->mat_idx2var_idx(var_idx);
967+
// Fixme, block_to_merge equals to starting block, this is a bug
968+
// if(idx == starting_block->block_id) return;
956969
ptr_PhasedBlock block_to_merge = phasing_window->blocks[idx];
970+
if (block_to_merge->block_id == starting_block->block_id)
971+
return;
957972
if (adj_mat(2 * prev_var_idx, 2 * var_idx) > 0)
958973
{
959974
if (block_to_merge->size() == 1)

spectral.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Spectral
8282

8383
std::map<uint, uint> phased_block_starts;
8484
std::set<uint> block_tobe_split;
85-
FragmentReader *fr; //Fragment matrix reader
85+
// FragmentReader *fr; //Fragment matrix reader
8686
std::vector<FragmentReader* > frs;
8787
BEDReader *frbed;
8888
HiCLinkerContainer hic_linker_container;
@@ -130,11 +130,11 @@ class Spectral
130130
CMatrix slice_submat(std::set<uint> &variants_mat, bool t);
131131
CMatrix slice_submat(std::set<uint> &variants_mat, bool t, CMatrix &adj_mat);
132132
void filter_inconsistency();
133-
void read_fragment_10x(int frIdx);
134-
void read_fragment(int frIdx);
135-
void read_fragment_hic(int frIdx);
136-
void read_fragment_pacbio(int frIdx);
137-
void read_fragment_nanopore(int frIdx);
133+
void read_fragment_10x(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph);
134+
void read_fragment(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph);
135+
void read_fragment_hic(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph);
136+
void read_fragment_pacbio(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph);
137+
void read_fragment_nanopore(int frIdx, ViewMap &weighted_graph, CViewMap &count_graph);
138138
void poss_phase_error_correction(uint block_start_idx);
139139
void fragment_supported_flipping_score(ptr_PhasedBlock &phased_block, Fragment & fragment, int *supporting_reads_count, double *supporting_weight_count, std::map<uint, std::set<uint>> &connection_map);
140140
int locate_block_valid_start(const Eigen::VectorXd &vec);

submodules/htslib

Submodule htslib updated 378 files

0 commit comments

Comments
 (0)