Skip to content

Commit a0e0e2d

Browse files
committed
cutadapt bugfixes + vserch tutorial
1 parent 3d7af99 commit a0e0e2d

5 files changed

Lines changed: 47 additions & 47 deletions

File tree

.gitignore

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
.Rhistory
2-
.Rapp.history
3-
4-
*.history
5-
JAMP/R/.Rapp.history
6-
JAMP/R/.Rapp.history
7-
*.history
8-
*.history
9-
JAMP/R/.Rapp.history
10-
JAMP/R/log.txt
11-
JAMP/R/.Rapp.history
12-
*.history
13-
.DS_Store
14-
*.history
15-
*.history
16-
*.history
1+
*.Rhistory
2+
*.Rapp.history
3+
*.DS_Store

JAMP/R/Cutadapt.R

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
# Cutadapt v0.1
22

3-
Cutadapt <- function(files="latest", forward=NA, reverse=NA, bothsides=F, anchoring=T, fastq=T, LDist=F, cores=1, delete_data=T, ambsequ=F, error=0.1, exe="cutadapt", exeU="usearch"){
3+
Cutadapt <- function(files="latest", forward=NA, reverse=NA, bothsides=F, anchoring=T, LDist=F, cores=1, delete_data=T, ambsequ=F, error=0.1, exe="cutadapt", exe2="vsearch", fastq=T){
44

55
# do checks
66
FW_only <- F
77
if (is.na(reverse[1])){FW_only <- T}
88

99

1010

11-
12-
13-
14-
15-
1611
folder <- Core(module="Cutadapt", delete_data=delete_data)
1712
cat(file="log.txt", c("Module Version: v0.2", "\n"), append=T, sep="\n")
1813

@@ -39,6 +34,7 @@ if(!fastq){ #rename to fasta if fastq=F
3934
new_names <- sub(".fastq", ".fasta", new_names)
4035
}
4136

37+
4238
# get primer sequences / names
4339
primers <- read.csv(paste(system.file(package="JAMP"), "/primers.csv", sep=""), stringsAsFactors=F)
4440

@@ -86,15 +82,15 @@ rw[i] <- paste(rev(comp(unlist(strsplit(rw[i], "")), forceToLower=F, ambiguous=T
8682

8783
# add: write down used primers in log!
8884
if (FW_only){
89-
cmd1 <- paste("-g ", if(anchoring){"^"}, fw, " -o \"", new_names, "\" \"", files, "\"", " -f ", if(fastq){"fastq"}else{"fasta"}, " --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, " --error-rate ", error, sep="") # forward adapter
85+
cmd1 <- paste("-g ", if(anchoring){"^"}, fw, " -o \"", new_names, "\" \"", files, "\"", " --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, " --error-rate ", error, sep="") # forward adapter
9086
files_to_delete <- c(files_to_delete, new_names)
9187

9288
temp <- paste("Starting to remove adapters (primers) on forward direction only ", length(cmd1), " files:", sep="")
9389
cat(file="log.txt", temp , append=T, sep="\n")
9490
message(temp)
9591
}else{
96-
cmd1 <- paste("-g ", if(anchoring){"^"}, fw, " -o ", folder, "/_data/temp.txt \"", files, "\"", " -f ", if(fastq){"fastq"}else{"fasta"}, " --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, " --error-rate ", error, sep="") # forward adapter
97-
cmd2 <- paste("-a ", rw, if(anchoring){"$"}," -o \"", new_names, "\" ", folder, "/_data/temp.txt -f ", if(fastq){"fastq"}else{"fasta"}, " --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, " --error-rate ", error, sep="") #rverse adapter
92+
cmd1 <- paste("-g ", if(anchoring){"^"}, fw, " -o ", folder, "/_data/temp.txt \"", files, "\"", " --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, " --error-rate ", error, sep="") # forward adapter
93+
cmd2 <- paste("-a ", rw, if(anchoring){"$"}," -o \"", new_names, "\" ", folder, "/_data/temp.txt ", " --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, " --error-rate ", error, sep="") #rverse adapter
9894
files_to_delete <- c(files_to_delete, new_names)
9995

10096
temp <- paste("Starting to remove adapters (primers) on both ends in ", length(cmd1), " files:", sep="")
@@ -129,28 +125,28 @@ cat(file=log_names[i], A, append=T, sep="\n")
129125
#cat(file=log_names[i], A, append=T, sep="\n")
130126

131127
# trimm RW
132-
rev_primer <- paste("-a ", rw[i], if(anchoring){"$"}," -o ", folder, "/_data/temp_A.txt ", folder, "/_data/temp.txt -f ", if(fastq){"fastq"}else{"fasta"}, " --discard-untrimmed --cores=", cores, sep="", if(ambsequ){" --match-read-wildcards"}, " --error-rate ", error) #rverse adapter
128+
rev_primer <- paste("-a ", rw[i], if(anchoring){"$"}," -o ", folder, "/_data/temp_A.txt ", folder, "/_data/temp.txt ", " --discard-untrimmed --cores=", cores, sep="", if(ambsequ){" --match-read-wildcards"}, " --error-rate ", error) #rverse adapter
133129

134130
A <- system2(exe, rev_primer, stdout=T, stderr=T)
135131
cat(file=log_names[i], A, append=T, sep="\n")
136132

137133
# build revcomp
138134

139135
revcom_cmd <- paste("-fastx_revcomp ", files[i], if(fastq){" -fastqout "} else {" -fastaout "}, folder, "/_data/temp2_RC.txt -label_suffix _RC", sep="")
140-
A <- system2(exeU, revcom_cmd, stdout=T, stderr=T)
136+
A <- system2(exe2, revcom_cmd, stdout=T, stderr=T)
141137

142-
cat(file=log_names[i], paste("usearch ", revcom_cmd, sep=""), append=T, sep="\n")
138+
cat(file=log_names[i], paste(exe2, revcom_cmd, sep=""), append=T, sep="\n")
143139
cat(file=log_names[i], A, append=T, sep="\n")
144140

145141
# cut primers again! simmillar commands
146142

147-
fw_primer_cmd <- paste("-g ", if(anchoring){"^"}, fw[i], " -o ", folder, "/_data/temp.txt ", folder, "/_data/temp2_RC.txt", " -f ", if(fastq){"fastq"}else{"fasta"}, " --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, sep="", " --error-rate ", error) # forward adapter
143+
fw_primer_cmd <- paste("-g ", if(anchoring){"^"}, fw[i], " -o ", folder, "/_data/temp.txt ", folder, "/_data/temp2_RC.txt", " --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, sep="", " --error-rate ", error) # forward adapter
148144

149145
A <- system2(exe, fw_primer_cmd, stdout=T, stderr=T)
150146
cat(file=log_names[i], A, append=T, sep="\n")
151147

152148

153-
rev_primer <- paste("-a ", rw[i], if(anchoring){"$"}," -o ", folder, "/_data/temp_B.txt ", folder, "/_data/temp.txt -f ", if(fastq){"fastq"}else{"fasta"}, " --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, sep="", " --error-rate ", error) #rverse adapter
149+
rev_primer <- paste("-a ", rw[i], if(anchoring){"$"}," -o ", folder, "/_data/temp_B.txt ", folder, "/_data/temp.txt --discard-untrimmed --cores=", cores, if(ambsequ){" --match-read-wildcards"}, sep="", " --error-rate ", error) #rverse adapter
154150

155151
A <- system2(exe, rev_primer, stdout=T, stderr=T)
156152
cat(file=log_names[i], A, append=T, sep="\n")

JAMP/R/Demultiplexing_shifted.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ write.csv(combos2, file= combinations, row.names=F)
9090

9191
combos <- combos2
9292

93-
temp <- paste("FileName detected! \"R1.txt\" and \"R2.txt\" added automatically to filenames. Please check the table used for primer combinations / filenames in \"", folder, "/combinations_auto_edited.csv\" for details.", sep="", "\n")
93+
temp <- paste("FileName detected! \"R1.fastq\" and \"R2.fastq\" added automatically to filenames. Please check the table used for primer combinations / filenames in \"", folder, "/combinations_auto_edited.csv\" for details.", sep="", "\n")
9494
message(temp)
9595
cat(file="log.txt", temp, append=T, sep="\n")
9696

JAMP/R/Minmax.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ max <- plusminus[1] + plusminus[2]
3939

4040

4141
# make cmd
42-
cmd <- paste("\"", files, "\" -o \"", folder, "/", new_names, "\" -f ", if(fastq){"fastq"}else{"fasta"}, if(!is.na(min[1])){" -m "}, if(!is.na(min[1])){min}, if(!is.na(min[1])){" -M "}, if(!is.na(min[1])){max}, sep="")
42+
cmd <- paste("\"", files, "\" -o \"", folder, "/", new_names, "\"", if(!is.na(min[1])){" -m "}, if(!is.na(min[1])){min}, if(!is.na(min[1])){" -M "}, if(!is.na(min[1])){max}, sep="")
4343

4444
files_to_delete <- c(files_to_delete, paste(folder, "/", new_names, sep=""))
4545

Tutorial/package_tutorial.R

100755100644
Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
# 170201 jamp pipeline, short tutorial
1+
# 12052021 jamp pipeline, short tutorial
22
#
3-
# download the raw data from and place it into the tutorial folder (Study we are looking at https://peerj.com/articles/3006/)
4-
# MiSeq Run1, R1 direction:
5-
# https://dx.doi.org/10.6084/m9.figshare.4039821.v1
6-
# MiSeq Run1, R2 direction:
7-
# https://dx.doi.org/10.6084/m9.figshare.4039860.v1
3+
84
#
95
# Installing dependencies needed fro JAMP
106
install.packages(c("bold", "XML", "seqinr", "devtools", "fastqcr"), dependencies=T)
@@ -13,8 +9,21 @@ library("devtools")
139
install_github("VascoElbrecht/JAMP", subdir="JAMP")
1410

1511

12+
# set workin directory
13+
setwd("~/Desktop/JAMP_pipeline/Tutorial")
14+
# download the raw data from and place it into the tutorial folder (Study we are looking at https://peerj.com/articles/3006/)
15+
# MiSeq Run1, R1 direction:
16+
# https://dx.doi.org/10.6084/m9.figshare.4039821.v1
17+
# MiSeq Run1, R2 direction:
18+
# https://dx.doi.org/10.6084/m9.figshare.4039860.v1
19+
20+
download.file("https://ndownloader.figshare.com/files/6503952", "16_S10_L001_R1_001_run1.fastq.gz")
21+
download.file("https://ndownloader.figshare.com/files/6503991", "16_S10_L001_R2_001_run1.fastq.gz")
22+
system2("gunzip", "16_S10_L001_R1_001_run1.fastq.gz")
23+
system2("gunzip", "16_S10_L001_R2_001_run1.fastq.gz")
24+
25+
1626

17-
setwd("~/Desktop/JAMP_pipeline")
1827
list.files()
1928

2029
library("JAMP")
@@ -30,33 +39,41 @@ Remove_last_folder()
3039
# In this example we are dealing with sequence raw data that is not jet demultiplexed. To demultiplex run:
3140
Demultiplexing_shifted(file1="16_S10_L001_R1_001_run1.fastq", file2="16_S10_L001_R2_001_run1.fastq", tags="_converter/indexe_1.csv", combinations="_converter/combos_1.csv")
3241

33-
# Paired end merging
34-
U_merge_PE(fastq_pctid=75)
42+
3543

3644
# check for PhiX
37-
system2("usearch", "-usearch_global A_Demultiplexing_shifted/_data/N_debris_r1.txt -db PhiX.fasta -id 0.9 -strand both -blast6out PhiX_table.txt")
45+
# only subsample 10000 reads
46+
if(T){
47+
system2("vsearch", "-fastx_subsample A_Demultiplexing_shifted/_data/N_debris_R1.fastq -fastaout A_Demultiplexing_shifted/_data/N_debris_R1.fasta -sample_size 10000")
48+
} else { # check all reads in read 1 for PhiX
49+
system2("paste", " - - - - < A_Demultiplexing_shifted/_data/N_debris_R1.fastq | cut -f 1,2 | sed 's/^@/>/' | tr \"\t\" \"\n\" > A_Demultiplexing_shifted/_data/N_debris_R1.fasta")
50+
}
51+
system2("vsearch", "-usearch_global A_Demultiplexing_shifted/_data/N_debris_R1.fasta -db PhiX.fasta -id 0.9 -strand both -blast6out PhiX_table.txt -maxrejects 1 -maxaccepts 1")
3852

3953

54+
# Paired end merging
55+
Merge_PE()
56+
4057

41-
# trimm primers
42-
Cutadapt(forward="GGWACWGGWTGAACWGTWTAYCCYCC", # mlCOIintF
43-
reverse="TANACYTCNGGRTGNCCRAARAAYCA", bothsides=T) # jgHCO, I (inosin) replaced with N
58+
# trimm primers (mlCOIintF and jgHCO)
59+
Cutadapt(forward="GGWACWGGWTGAACWGTWTAYCCYCC", reverse="TAIACYTCIGGRTGICCRAARAAYCA", bothsides=T)
4460
#by using "bothsides=T", forward or reverse primers are detected on both ends. This is not nessesary for fusion primers.
4561

4662
# discard with non target length
4763
Minmax(min=(313-10), max=(313+10))
4864

4965
# discard reads above 1 expected error
50-
U_max_ee(max_ee=1)
66+
Max_ee(max_ee=1)
5167

5268
# subsample to lowest sample size, should be done if samples are widely different in sequencing depth (as one starts with)
69+
# needs to be umdated, right now still on userch! Vserch not supported right now
5370
U_subset(sample_size=60000)
5471

5572

5673

5774

5875
#cluster OTUs
59-
U_cluster_otus(filter=0.01)
76+
Cluster_otus(filter=0.01)
6077
file.rename("G_U_cluster_otus", "G_U_cluster_otus - 60k")
6178

6279
#cluster OTUs (without subsetting)

0 commit comments

Comments
 (0)