annotate export_to_fastq/export_to_fastq_past.R @ 0:97792524cc9c default tip

Migrated tool version 0.1 from old tool shed archive to new tool shed repository
author louise
date Tue, 07 Jun 2011 17:21:49 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
1 my.args <- commandArgs(trailingOnly = TRUE)
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
2 # ----- Check input and output directories -----
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
3 if(!file.exists(my.args[1])){
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
4 stop("The provided project directory does not exist!")
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
5 }
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
6 inputDirectory=my.args[1] #Directory where input data are. (e.g export or fastq ...)
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
7
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
8 output_file = my.args[3]
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
9
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
10 threshold=as.numeric(my.args[2]) #threshold for nFilter
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
11
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
12 #print(my.args)
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
13
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
14 library(ShortRead)
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
15 #source('/home/galaxy/galaxy_dev/tools/EMBL_tools/HTS_helper_src_for_export_to_fastq.R')
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
16
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
17 ####Solution temporaire, chastityFilter sera dans le RNASeq package
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
18 chastityFilter <- function(.name="Illumina Chastity Filter")
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
19 {
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
20 srFilter(function(x){
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
21 if(any(rownames(varMetadata(alignData(x))) == "filtering")){
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
22 keep<-alignData(x)$filtering=="Y"
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
23 } else {
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
24 warning(paste("The '",.name,"' filter is only valid for Illumina reads.",sep=""))
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
25 keep<-rep(TRUE,length(x))
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
26 }
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
27 return(keep)
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
28 },name=.name)
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
29 }
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
30
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
31 "summarize.by.transcripts" <- function(sample,annotation){
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
32
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
33 transcripts <- do.call(rbind,lapply(names(sample),function(chr,sample,annotation){
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
34 counts<-stats:::aggregate(sample[[chr]],list(transcript=annotation[chr]$transcript),sum)
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
35 },sample,annotation))
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
36
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
37 colnames(transcripts)[2] <- "counts"
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
38
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
39 return(transcripts)
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
40 }
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
41 ###
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
42
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
43 #----- FILTER ----
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
44 filter<- compose(chastityFilter(),nFilter(threshold=threshold))
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
45
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
46 #----- ALIGN ----
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
47 # call the readAligned function with this filter
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
48 aln<-readAligned(inputDirectory, type='SolexaExport',filter=filter, withAll=TRUE )
97792524cc9c Migrated tool version 0.1 from old tool shed archive to new tool shed repository
louise
parents:
diff changeset
49 writeFastq(aln,file=output_file,mode='a')