# Remove full and partial adapters from a ShortReadQ object

`adapter_filter.Rd`

This program can remove adapters and partial adapters from 3' and 5', using the functions `trimLRPatterns` The program extends the methodology of the `trimLRPatterns` function of Biostrings, being also capable of removing adapters present within reads and with other additional otpions (e.g., threshold of minimum number of bases for trimming). For a given position in the read, the two Biostrings functions return TRUE when a match is present between a substring of the read and the adapter. As `trimLRPatterns` , adapter_filter also selects region and goes up to the end of the sequence in the corresponding flank as the best match. The default error rate is 0.2. If several valid matches are found, the function removes the largest subsequence. Adapters can be anchored or not. When indels are allowed, the second method uses the 'edit distance' between the subsequences and the adapter

    adapter_filter(input, Lpattern = "", Rpattern = "", rc.L = FALSE,
      rc.R = FALSE, first = c("R", "L"), with_indels = FALSE,
      error_rate = 0.2, anchored = TRUE, fixed = "subject",
      remove_zero = TRUE, checks = TRUE, min_match_flank = 3L, ...)

## Arguments

input | `ShortReadQ` object
Lpattern | 5' pattern (character or `DNAString` object)
Rpattern | 3' pattern (character or `DNAString` object)
rc.L | Reverse complement Lpattern? default FALSE
rc.R | Reverse complement Rpatter? default FALSE
first | trim first right('R') or left ('L') side of sequences when both Lpattern and Rpattern are passed
with_indels | Allow indels? This feature is available only when the error_rate is not null
error_rate | Error rate (value in the range [0, 1] The error rate is the proportion of mismatches allowed between the adapter and the aligned portion of the subject. For a given adapter A, the number of allowed mismatches between each subsequence s of A and the subject is computed as: error_rate * L_s, where L_s is the length of the subsequence s
anchored | Adapter or partial adapter within sequence (anchored = FALSE, default) or only in 3' and 5' terminals? (anchored = TRUE)
fixed | Parameter passed to `trimLRPatterns` Default 'subject', ambiguities in the pattern only are interpreted as wildcard. See the argument fixed in `trimLRPatterns`
remove_zero | Remove zero-length sequences? Default TRUE
checks | Perform checks? Default TRUE
min_match_flank | Do not trim in flanks of the subject, if a match has min_match_flank of less length. Default 1L (only trim with >=2 coincidences in a flank match)
... | additional parameters passed to `trimLRpatterns`

## Value

Edited `DNAString` or `DNAStringSet` object

Filtered `ShortReadQ` object

## Examples

    require('Biostrings')#> Loading required package: Biostrings#> Loading required package: BiocGenerics#> Loading required package: parallel#>
    #> Attaching package: ‘BiocGenerics’#> The following objects are masked from ‘package:parallel’:
    #>
    #>     clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    #>     clusterExport, clusterMap, parApply, parCapply, parLapply,
    #>     parLapplyLB, parRapply, parSapply, parSapplyLB#> The following objects are masked from ‘package:stats’:
    #>
    #>     IQR, mad, sd, var, xtabs#> The following objects are masked from ‘package:base’:
    #>
    #>     anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    #>     dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    #>     grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    #>     order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    #>     rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    #>     union, unique, unsplit, which, which.max, which.min#> Loading required package: S4Vectors#> Loading required package: stats4#>
    #> Attaching package: ‘S4Vectors’#> The following object is masked from ‘package:base’:
    #>
    #>     expand.grid#> Loading required package: IRanges#> Loading required package: XVector#>
    #> Attaching package: ‘Biostrings’#> The following object is masked from ‘package:base’:
    #>
    #>     strsplitrequire('ShortRead')#> Loading required package: ShortRead#> Loading required package: BiocParallel#> Loading required package: Rsamtools#> Loading required package: GenomeInfoDb#> Loading required package: GenomicRanges#> Loading required package: GenomicAlignments#> Loading required package: SummarizedExperiment#> Loading required package: Biobase#> Welcome to Bioconductor
    #>
    #>     Vignettes contain introductory material; view with
    #>     'browseVignettes()'. To cite Bioconductor, see
    #>     'citation("Biobase")', and for packages 'citation("pkgname")'.#> Loading required package: DelayedArray#> Loading required package: matrixStats#>
    #> Attaching package: ‘matrixStats’#> The following objects are masked from ‘package:Biobase’:
    #>
    #>     anyMissing, rowMedians#>
    #> Attaching package: ‘DelayedArray’#> The following objects are masked from ‘package:matrixStats’:
    #>
    #>     colMaxs, colMins, colRanges, rowMaxs, rowMins, rowRanges#> The following object is masked from ‘package:Biostrings’:
    #>
    #>     type#> The following objects are masked from ‘package:base’:
    #>
    #>     aperm, apply, rowsum
    # create 6 sequences of width 43
    set.seed(10)
    input <- random_seq(6, 43)

    # add adapter in 3'
    adapter <- "ATCGACT"

    input <- paste0(input, as.character(DNAString(adapter)))
    input <- DNAStringSet(input)

    # create qualities of width 50
    set.seed(10)
    input_q <- random_qual(c(30,40), slength = 6, swidth = 50,
    encod = 'Sanger')

    # create names
    input_names <- seq_names(length(input))

    # create ShortReadQ object
    my_read <- ShortReadQ(sread = input, quality = input_q, id = input_names)

    # trim adapter
    filtered <- adapter_filter(my_read, Rpattern = adapter)

    # look at the filtered sequences
    sread(filtered)#>   A DNAStringSet instance of length 6
    #>     width seq
    #> [1]    43 TGGTCCGGTGTTCTGGCGGAATAGGTACAGTCCAGTAATTGCC
    #> [2]    43 TCCCGCAGACGCTGGGTCCGGAATGCCCTTTCTGAGCAGCTCC
    #> [3]    43 AGCCGTTTGACTTCGCGGAAAGTGAACTTAGATTCGGTCCTGA
    #> [4]    43 AACACGGTACTTCCACAGTCAACCCGCCGACTTGGAGAATTTA
    #> [5]    43 TTAGCCGGGCGGTTATTCCCCTAGTGATCTTACTAAGATTTGC
    #> [6]    43 AATACCTAAGCGAAGTGACAGATATGTTCGTCATTCATCCAGG