From 7bdd09de649ac34512369f509c9e4d3a4b5c1d08 Mon Sep 17 00:00:00 2001 From: Hasindu Gamaarachchi Date: Mon, 25 Aug 2025 21:00:38 +1000 Subject: [PATCH 1/2] noncpg --- src/genread.c | 36 +++++++++++++++++++++++++++++++++++- src/sim.c | 5 ++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/genread.c b/src/genread.c index df204b4..577b7a3 100644 --- a/src/genread.c +++ b/src/genread.c @@ -240,6 +240,40 @@ static void methylate_dna(core_t *core, int32_t ref_len, int32_t ref_pos, int32_ return; } + + +void methylate_all_c_dna(core_t *core, int32_t ref_len, int32_t ref_pos, int32_t rlen, char c, char *seq, int seq_i, int tid){ + if(core->ref->ref_meth[seq_i]){ + for(int i=0; iref->ref_seq[seq_i][ref_pos+i]; + int p = -1; + if(c == '+' && base == 'C'){ + p = i; + } else if (c == '-' && base == 'G') { + p = rlen - i - 2; + } + + if(p != -1){ + if(!(p>=0 && prand_meth[tid]) * 254; + if( methr <= core->ref->ref_meth[seq_i][ref_pos+i]){ + seq[p] = 'M'; + } + } + } + } + } + return; +} + + static char *gen_read_dna(core_t *core, char **ref_id, int32_t *ref_len, int32_t *ref_pos, int32_t *rlen, char *c, int tid){ char *seq = NULL; @@ -274,7 +308,7 @@ static char *gen_read_dna(core_t *core, char **ref_id, int32_t *ref_len, int32_t } if(core->opt.meth_freq){ - methylate_dna(core, *ref_len, *ref_pos, *rlen, *c, seq, seq_i, tid); + methylate_all_c_dna(core, *ref_len, *ref_pos, *rlen, *c, seq, seq_i, tid); } return seq; diff --git a/src/sim.c b/src/sim.c index 6de3be2..7dd854d 100644 --- a/src/sim.c +++ b/src/sim.c @@ -508,7 +508,7 @@ void fake_uuid(char *read_id, int64_t num){ char *gen_read(core_t *core, char **ref_id, int32_t *ref_len, int32_t *ref_pos, int32_t *rlen, char *c, int8_t rna, int tid); int16_t *gen_sig(core_t *core, const char *read, int32_t len, double *offset, double *median_before, int64_t *len_raw_signal, int8_t rna, int tid, aln_t *aln); - +void methylate_all_c_dna(core_t *core, int32_t ref_len, int32_t ref_pos, int32_t rlen, char c, char *seq, int seq_i, int tid); /* process the ith read in the batch db */ void work_per_single_read(core_t* core,db_t* db, int32_t i, int tid) { @@ -547,6 +547,9 @@ void work_per_single_read(core_t* core,db_t* db, int32_t i, int tid) { strand = '+'; ref_pos_st = 0; ref_pos_end = rlen; + if(core->opt.meth_freq){ + methylate_all_c_dna(core, rlen, ref_pos_st, rlen, strand, seq, core->total_reads+i, tid); + } } else { seq=gen_read(core, &rid, &ref_len, &ref_pos_st, &rlen, &strand, rna, tid); ref_pos_end = ref_pos_st+rlen; From d4c5403f7ca6606dbb4537d11c477422dc899e2f Mon Sep 17 00:00:00 2001 From: Hasindu Gamaarachchi Date: Wed, 25 Feb 2026 23:14:28 +1100 Subject: [PATCH 2/2] --meth-all-ctx --- src/genread.c | 8 ++++++-- src/sim.c | 14 ++++++++++++-- src/sq.h | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/genread.c b/src/genread.c index 577b7a3..ace0602 100644 --- a/src/genread.c +++ b/src/genread.c @@ -204,7 +204,7 @@ static inline int get_rlen(core_t *core, int tid){ return len; } -static void methylate_dna(core_t *core, int32_t ref_len, int32_t ref_pos, int32_t rlen, char c, char *seq, int seq_i, int tid){ +void methylate_dna(core_t *core, int32_t ref_len, int32_t ref_pos, int32_t rlen, char c, char *seq, int seq_i, int tid){ if(core->ref->ref_meth[seq_i]){ for(int i=0; iopt.meth_freq){ - methylate_all_c_dna(core, *ref_len, *ref_pos, *rlen, *c, seq, seq_i, tid); + if(core->opt.flag & SQ_ALL_CTX){ + methylate_all_c_dna(core, *ref_len, *ref_pos, *rlen, *c, seq, seq_i, tid); + } else { + methylate_dna(core, *ref_len, *ref_pos, *rlen, *c, seq, seq_i, tid); + } } return seq; diff --git a/src/sim.c b/src/sim.c index dd098e1..e9cd9a6 100644 --- a/src/sim.c +++ b/src/sim.c @@ -512,6 +512,7 @@ void fake_uuid(char *read_id, int64_t num){ char *gen_read(core_t *core, char **ref_id, int32_t *ref_len, int32_t *ref_pos, int32_t *rlen, char *c, int8_t rna, int tid); int16_t *gen_sig(core_t *core, const char *read, int32_t len, double *offset, double *median_before, int64_t *len_raw_signal, int8_t rna, int tid, aln_t *aln); +void methylate_dna(core_t *core, int32_t ref_len, int32_t ref_pos, int32_t rlen, char c, char *seq, int seq_i, int tid); void methylate_all_c_dna(core_t *core, int32_t ref_len, int32_t ref_pos, int32_t rlen, char c, char *seq, int seq_i, int tid); /* process the ith read in the batch db */ @@ -552,7 +553,11 @@ void work_per_single_read(core_t* core,db_t* db, int32_t i, int tid) { ref_pos_st = 0; ref_pos_end = rlen; if(core->opt.meth_freq){ - methylate_all_c_dna(core, rlen, ref_pos_st, rlen, strand, seq, core->total_reads+i, tid); + if (opt.flag & SQ_ALL_CTX) { + methylate_all_c_dna(core, rlen, ref_pos_st, rlen, strand, seq, core->total_reads+i, tid); + } else{ + methylate_dna(core, rlen, ref_pos_st, rlen, strand, seq, core->total_reads+i, tid); + } } } else { seq=gen_read(core, &rid, &ref_len, &ref_pos_st, &rlen, &strand, rna, tid); @@ -706,7 +711,8 @@ static struct option long_options[] = { {"cdna", no_argument, 0, 0 }, //34 cdna {"ont-friendly", required_argument, 0, 0}, //35 ont-friendly {"meth-freq", required_argument, 0, 0 }, //36 meth-freq - {"meth-model", required_argument, 0, 0 }, //37 meth-model + {"meth-model", required_argument, 0, 0 }, //37 meth-model + {"meth-all-ctx", required_argument, 0, 0 }, //38 meth-all-ctx {0, 0, 0, 0}}; @@ -771,6 +777,7 @@ static void print_help(FILE *fp_help, opt_t opt, profile_t p, int64_t nreads) { fprintf(fp_help," --median-before-std FLOAT Median before standard deviation [%.1f]\n",p.median_before_std); fprintf(fp_help," --kmer-model FILE custom nucleotide k-mer model file (format similar to f5c models)\n"); fprintf(fp_help," --meth-model FILE custom methylation k-mer model file (format similar to f5c models)\n"); + fprintf(fp_help," --meth-all-ctx=yes/no relax CpG condition (for custom meth-model)\n"); fprintf(fp_help,"\n"); fprintf(fp_help,"See the manual page on GitHub for more details, options and the format of input/output files.\n"); @@ -1004,6 +1011,9 @@ int sim_main(int argc, char* argv[], double realtime0) { } else if (c == 0 && longindex == 37){ //meth model opt.meth_model_file = optarg; //WARNING("%s","Option --meth-model is experimental. Please report any issues.") + } else if (c == 0 && longindex == 38){ //all context + WARNING("%s","Option --meth-all-ctx is experimental. Please report any issues.") + yes_or_no(&opt, SQ_ALL_CTX, longindex, optarg, 1); } else if (c == '?'){ exit(EXIT_FAILURE); } else { diff --git a/src/sq.h b/src/sq.h index c058770..2755c76 100644 --- a/src/sq.h +++ b/src/sq.h @@ -41,6 +41,7 @@ #define SQ_CDNA 0x200 //CDNA #define SQ_ONT 0x400 //ont friendly #define SQ_PROM 0x800 //is a promethion +#define SQ_ALL_CTX 0x1000 //all context instead of CpG #define WORK_STEAL 1 //simple work stealing enabled or not (no work stealing mean no load balancing) #define STEAL_THRESH 1 //stealing threshold