Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ==== Open the files and get sequence
- library(ShortRead)
- dataDir <- "/home/retureau/Bureau/sampleData/output"
- fls <- list.files(dataDir, "fastq$", full=TRUE) # select two fastq files and store their paths
- names(fls) <- sub(".fastq", "", basename(fls)) # name the columns. basename(fls) give the "name.fastq" and sub remove ".fastq".
- fq <- lapply(fls, readFastq) # apply readFastq func for both fastq file (store them in fq)
- AvgQty <- function(rFq)
- {
- # Calculate the average quality of each read
- rowMeans(as(quality(rFq), "matrix"))
- }
- Rtrim <- function(fq)
- {
- qtyMat <- sapply(fq, AvgQty)
- outputDir <- "/home/retureau/Bureau/sampleData" # output directory
- # full path + new name for output files
- pairedFile <- c(file.path(outputDir, paste0(names(fq)[1], "_paired.fastq")), file.path(outputDir, paste0(names(fq)[2], "_paired.fastq")))
- unpairedFile <- c(file.path(outputDir, paste0(names(fq)[1], "_funpaired.fastq")), file.path(outputDir, paste0(names(fq)[2], "_runpaired.fastq")))
- # dim(qtyMat)[1]
- good_paired_quality = which(qtyMat[,1]>20 & qtyMat[,2]>20)
- if (length(good_paired_quality) > 0){
- writeFastq(fq[[1]][good_paired_quality], pairedFile[1], mode='w')
- writeFastq(fq[[2]][good_paired_quality], pairedFile[2])
- }
- good_unpaired_qual_1=which(qtyMat[, 1]>20 & qtyMat[,2]<=20)
- if (length(good_unpaired_qual_1) > 0)
- writeFastq(fq[[1]][good_unpaired_qual_1], unpairedFile[1])
- good_unpaired_qual_2=which(qtyMat[,1]<=20 & qtyMat[,2]>20)
- if (length(good_unpaired_qual_2) > 0)
- writeFastq(fq[[2]][good_unpaired_qual_2], unpairedFile[2])
- }
Advertisement
Add Comment
Please, Sign In to add comment