Skip to content

Commit ec5e1c5

Browse files
counts: Formatting and removing unused code
1 parent 429b4c5 commit ec5e1c5

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

src/analysis/methcounts.cpp

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -183,40 +183,36 @@ get_tag_from_genome(const string &s, const size_t pos) {
183183
return 4; // shouldn't be used for anything
184184
}
185185

186-
187186
/* This "has_mutated" function looks on the opposite strand to see
188187
* if the apparent conversion from C->T was actually already in the
189188
* DNA because of a mutation or SNP.
190189
*/
191190
static bool
192191
has_mutated(const char base, const CountSet &cs) {
193192
static const double MUTATION_DEFINING_FRACTION = 0.5;
194-
return is_cytosine(base) ?
195-
(cs.nG < MUTATION_DEFINING_FRACTION*(cs.neg_total())) :
196-
(cs.pG < MUTATION_DEFINING_FRACTION*(cs.pos_total()));
193+
return is_cytosine(base)
194+
? (cs.nG < MUTATION_DEFINING_FRACTION * (cs.neg_total()))
195+
: (cs.pG < MUTATION_DEFINING_FRACTION * (cs.pos_total()));
197196
}
198197

199-
200198
static inline bool
201199
is_cpg_site(const string &s, const size_t pos) {
202-
return (is_cytosine(s[pos]) ? is_guanine(s[pos + 1]) :
203-
(is_guanine(s[pos]) ?
204-
(pos > 0 && is_cytosine(s[pos - 1])) : false));
200+
return is_cytosine(s[pos])
201+
? is_guanine(s[pos + 1])
202+
: (is_guanine(s[pos]) ? (pos > 0 && is_cytosine(s[pos - 1]))
203+
: false);
205204
}
206205

207-
208206
static inline size_t
209207
get_chrom_id(const string &chrom_name,
210208
const unordered_map<string, size_t> &cl) {
211-
212209
auto the_chrom(cl.find(chrom_name));
213210
if (the_chrom == end(cl))
214211
throw dnmt_error("could not find chrom: " + chrom_name);
215212

216213
return the_chrom->second;
217214
}
218215

219-
220216
static const char *tag_values[] = {
221217
"CpG", // 0
222218
"CHH", // 1
@@ -253,39 +249,26 @@ write_output(const bamxx::bam_header &hdr, bamxx::bgzf_file &out,
253249
if (CPG_ONLY && the_tag != 0) continue;
254250

255251
const bool is_c = is_cytosine(base);
256-
const double unconverted = is_c ?
257-
counts[i].unconverted_cytosine() : counts[i].unconverted_guanine();
258-
const double converted = is_c ?
259-
counts[i].converted_cytosine() : counts[i].converted_guanine();
252+
const double unconverted = is_c ? counts[i].unconverted_cytosine()
253+
: counts[i].unconverted_guanine();
254+
const double converted =
255+
is_c ? counts[i].converted_cytosine() : counts[i].converted_guanine();
260256
const bool mut = has_mutated(base, counts[i]);
261257
const size_t n_reads = unconverted + converted;
262258
buf.clear();
263259
// ADS: here is where we make an MSite, but not using MSite
264-
buf << sam_hdr_tid2name(hdr, tid) << '\t'
265-
<< i << '\t'
260+
buf << sam_hdr_tid2name(hdr, tid) << '\t' << i << '\t'
266261
<< (is_c ? '+' : '-') << '\t'
267262
<< tag_values[tag_with_mut(the_tag, mut)] << '\t'
268-
<< (n_reads > 0 ? unconverted/n_reads : 0.0) << '\t'
269-
<< n_reads << '\n';
263+
<< (n_reads > 0 ? unconverted / n_reads : 0.0) << '\t' << n_reads
264+
<< '\n';
270265
if (!out.write(buf.c_str(), buf.tellp()))
271266
throw dnmt_error("error writing output");
272267
}
273268
}
274269
}
275270

276271

277-
/* ADS: was tempted to use these until I passed in a "b++"... */
278-
// #define get_tid(b) ((b)->core.tid)
279-
// #define get_rlen(b) (bam_cigar2rlen((b)->core.n_cigar, bam_get_cigar(b)))
280-
// #define get_pos(b) ((b)->core.pos)
281-
// #define get_qlen(b) ((b)->core.l_qseq)
282-
283-
284-
285-
286-
287-
288-
289272
static void
290273
count_states_pos(const bam_rec &aln, vector<CountSet> &counts) {
291274
/* Move through cigar, reference and read positions without

0 commit comments

Comments
 (0)