Skip to content

Commit

Permalink
add in code for revcomping primers; setup for cutadapt
Browse files Browse the repository at this point in the history
  • Loading branch information
cjfields committed Jan 14, 2025
1 parent e4f9da4 commit 11dcf3c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions subworkflows/local/filter_and_trim.nf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ workflow FILTER_AND_TRIM {
ch_trimmed_R1 = Channel.empty()
ch_trimmed_R2 = Channel.empty()

for_primer = params.for_primer
for_primer_rc = ""
rev_primer = params.rev_primer
rev_primer_rc = ""

if (for_primer && rev_primer) {
for_primer_rc = reverse_complement(for_primer)
rev_primer_rc = reverse_complement(rev_primer)
}

if (params.platform == "pacbio") {

// TODO: this could be modified/split into a `cutadapt`-only step; there
Expand Down Expand Up @@ -79,3 +89,29 @@ workflow FILTER_AND_TRIM {
trimmed_report = MERGE_TRIM_TABLES.out.trimmed_report // channel: [ RDS ]
trimmed_infer = ch_trimmed_infer
}

def reverse_complement(primer) {
// returns the revcomp, handles IUPAC ambig codes
// tr "[ATGCUNYRSWKMBDHV]" "[TACGANRYSWMKVHDB]"
return primer.reverse().collect {
switch (it) {
case 'A': return 'T'
case 'T': return 'A'
case 'G': return 'C'
case 'C': return 'G'
case 'U': return 'A'
case 'N': return 'N'
case 'Y': return 'R'
case 'R': return 'Y'
case 'S': return 'S'
case 'W': return 'W'
case 'K': return 'M'
case 'M': return 'K'
case 'B': return 'V'
case 'D': return 'H'
case 'H': return 'D'
case 'V': return 'B'
default: return it // handle invalid characters if needed
}
}.join('')
}

0 comments on commit 11dcf3c

Please sign in to comment.