Guest User

Untitled

a guest
Jun 10th, 2014
1,536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.61 KB | None | 0 0
  1. # ==== Open the files and get sequence
  2.  
  3. library(ShortRead)
  4.  
  5.  
  6. dataDir <- "/home/retureau/Bureau/sampleData/output"
  7. fls <- list.files(dataDir, "fastq$", full=TRUE)  # select two fastq files and store their paths
  8. names(fls) <- sub(".fastq", "", basename(fls))  # name the columns. basename(fls) give the "name.fastq" and sub remove ".fastq".
  9.  
  10. fq <- lapply(fls, readFastq)   # apply readFastq func for both fastq file (store them in fq)
  11.  
  12. AvgQty <- function(rFq)
  13. {
  14.   # Calculate the average quality of each read
  15.   rowMeans(as(quality(rFq), "matrix"))
  16. }
  17.  
  18.  
  19. Rtrim <- function(fq)
  20. {
  21.   qtyMat <- sapply(fq, AvgQty)
  22.  
  23.   outputDir <- "/home/retureau/Bureau/sampleData"  # output directory
  24.  
  25.   # full path + new name for output files
  26.   pairedFile <- c(file.path(outputDir, paste0(names(fq)[1], "_paired.fastq")), file.path(outputDir,  paste0(names(fq)[2], "_paired.fastq")))
  27.   unpairedFile <- c(file.path(outputDir, paste0(names(fq)[1], "_funpaired.fastq")), file.path(outputDir,  paste0(names(fq)[2], "_runpaired.fastq")))
  28.  
  29.   #  dim(qtyMat)[1]
  30.   good_paired_quality = which(qtyMat[,1]>20 & qtyMat[,2]>20)
  31.   if (length(good_paired_quality) > 0){
  32.     writeFastq(fq[[1]][good_paired_quality], pairedFile[1], mode='w')
  33.     writeFastq(fq[[2]][good_paired_quality], pairedFile[2])
  34.   }
  35.   good_unpaired_qual_1=which(qtyMat[, 1]>20 & qtyMat[,2]<=20)
  36.   if (length(good_unpaired_qual_1) > 0)
  37.     writeFastq(fq[[1]][good_unpaired_qual_1], unpairedFile[1])
  38.  
  39.   good_unpaired_qual_2=which(qtyMat[,1]<=20 & qtyMat[,2]>20)
  40.   if (length(good_unpaired_qual_2) > 0)
  41.     writeFastq(fq[[2]][good_unpaired_qual_2], unpairedFile[2])
  42. }
Advertisement
Add Comment
Please, Sign In to add comment