X-Git-Url: https://git.donarmstrong.com/?p=rsem.git;a=blobdiff_plain;f=wiggle.cpp;h=00dcce8d431edc2c38c0891d17b8085dbcbac25b;hp=65a3d4a783e1ffd44e3b534c890113138aff8aee;hb=HEAD;hpb=5fd66ada6c610981dcecd50e5e41436e0458b110 diff --git a/wiggle.cpp b/wiggle.cpp index 65a3d4a..00dcce8 100644 --- a/wiggle.cpp +++ b/wiggle.cpp @@ -1,16 +1,27 @@ #include #include #include +#include #include #include "sam/bam.h" #include "sam/sam.h" +#include "utils.h" #include "wiggle.h" +bool no_fractional_weight = false; + void add_bam_record_to_wiggle(const bam1_t *b, Wiggle& wiggle) { - uint8_t *p_tag = bam_aux_get(b, "ZW"); - float w = (p_tag != NULL ? bam_aux2f(p_tag) : 1.0); + double w; + + if (no_fractional_weight) w = 1.0; + else { + uint8_t *p_tag = bam_aux_get(b, "ZW"); + if (p_tag == NULL) return; + w = bam_aux2f(p_tag); + } + int pos = b->core.pos; uint32_t *p = bam1_cigar(b); @@ -41,23 +52,23 @@ void build_wiggles(const std::string& bam_filename, bool *used = new bool[header->n_targets]; memset(used, 0, sizeof(bool) * header->n_targets); - int cur_tid = -1; //current tid; - int cnt = 0; - bam1_t *b = bam_init1(); - Wiggle wiggle; + int cur_tid = -1; //current tid; + HIT_INT_TYPE cnt = 0; + bam1_t *b = bam_init1(); + Wiggle wiggle; while (samread(bam_in, b) >= 0) { if (b->core.flag & 0x0004) continue; if (b->core.tid != cur_tid) { if (cur_tid >= 0) { used[cur_tid] = true; processor.process(wiggle); } cur_tid = b->core.tid; - wiggle.name = header->target_name[cur_tid]; - wiggle.length = header->target_len[cur_tid]; - wiggle.read_depth.assign(wiggle.length, 0.0); + wiggle.name = header->target_name[cur_tid]; + wiggle.length = header->target_len[cur_tid]; + wiggle.read_depth.assign(wiggle.length, 0.0); } - add_bam_record_to_wiggle(b, wiggle); + add_bam_record_to_wiggle(b, wiggle); ++cnt; - if (cnt % 1000000 == 0) fprintf(stderr, "%d FIN\n", cnt); + if (cnt % 1000000 == 0) std::cout<< cnt<< std::endl; } if (cur_tid >= 0) { used[cur_tid] = true; processor.process(wiggle); } @@ -93,14 +104,14 @@ void UCSCWiggleTrackWriter::process(const Wiggle& wiggle) { sp = ep = -1; for (size_t i = 0; i < wiggle.length; i++) { - if (wiggle.read_depth[i] > 0) { + if (wiggle.read_depth[i] >= 0.0095) { ep = i; } else { if (sp < ep) { ++sp; fprintf(fo, "fixedStep chrom=%s start=%d step=1\n", wiggle.name.c_str(), sp + 1); - for (int j = sp; j <= ep; j++) fprintf(fo, "%.7g\n", wiggle.read_depth[j]); + for (int j = sp; j <= ep; j++) fprintf(fo, "%.2f\n", wiggle.read_depth[j]); } sp = i; } @@ -108,7 +119,7 @@ void UCSCWiggleTrackWriter::process(const Wiggle& wiggle) { if (sp < ep) { ++sp; fprintf(fo, "fixedStep chrom=%s start=%d step=1\n", wiggle.name.c_str(), sp + 1); - for (int j = sp; j <= ep; j++) fprintf(fo, "%.7g\n", wiggle.read_depth[j]); + for (int j = sp; j <= ep; j++) fprintf(fo, "%.2f\n", wiggle.read_depth[j]); } }