Problems with Automatic Manifest Maker (Rlang)

Hello! Loving the script!
I think it would be worth a mention so the novices such as myself remember to make sure the script is being interpreted by R and not bash.
Unfortunately I get this error when I try to run

(R-Env) [email protected]:~/Desktop/MACE_DEMUX_FASTQs/barcode07$ ~/Taxonomy.R
Error in [<-.data.frame(*tmp*, “direction”, value = “forward”) :
replacement has 1 row, data has 0
Calls: [<- -> [<-.data.frame
Execution halted

I’ve never done anything in R before so was hoping you could lend a hand to the meek!

Cheers!!

Hi all!
please see https://stackoverflow.com/questions/52496914/tidyverse-conflicts-with-automatic-manifest-maker/52498031?noredirect=1#comment91937434_52498031
for ammendments

here is the ammended script for anyone who is interested. make sure you have your data in a sub directory called “Data” and edit ~/Desktop/MACE_DEMUX_FASTQs/barcode11 to be your parent directory

#!/usr/bin/env Rscript
library(tidyverse)

data_path <- paste("~/Desktop/MACE_DEMUX_FASTQs/barcode11", “Data”, sep = “/”)
SamplesF <- list.files(path = data_path, pattern = “*.R1.fastq.gz”, all.files = FALSE,
full.names = TRUE, recursive = FALSE,
ignore.case = FALSE, include.dirs = FALSE, no… = FALSE)

TabF <- as.data.frame(SamplesF)

PathF <- data.frame(lapply(TabF, function(TabF) {gsub(“Data/”, “$PWD/N/”, TabF)}))
PathF <- data.frame(lapply(PathF, function(PathF) {gsub(“fastq.gz”, “fastq.gip”, PathF)}))

names(PathF)[names(PathF)==“SamplesF”] <- “absolute-filepath”

PathF[‘direction’]=‘forward’

PathF[‘sample-id’]= SamplesF

PathF <- data.frame(lapply(PathF, function(PathF) {gsub(“Data/”, “sample-”, PathF)}))
PathF <- data.frame(lapply(PathF, function(PathF) {gsub(".R1.fastq.gz", “”, PathF)}))
PathF <- data.frame(lapply(PathF, function(PathF) {gsub(“fastq.gip”, “fastq.gz”, PathF)}))
PathF <- data.frame(lapply(PathF, function(PathF) {gsub("/N/", “/Data/”, PathF)}))

PathF <- PathF[,c(3,1,2)]

SamplesR <- list.files(path = data_path, pattern = “*.R2.fastq.gz”, all.files = FALSE,
full.names = TRUE, recursive = FALSE,
ignore.case = FALSE, include.dirs = FALSE, no… = FALSE)

TabR <- as.data.frame(SamplesR)

PathR <- data.frame(lapply(TabR, function(TabR) {gsub(“Data/”, “$PWD/N/”, TabR)}))
PathR <- data.frame(lapply(PathR, function(PathR) {gsub(“fastq.gz”, “fastq.gip”, PathR)}))

names(PathR)[names(PathR)==“SamplesR”] <- “absolute-filepath”

PathR[‘direction’]=‘reverse’

PathR[‘sample-id’]= SamplesR

PathR <- data.frame(lapply(PathR, function(PathR) {gsub(“Data/”, “sample-”, PathR)}))
PathR <- data.frame(lapply(PathR, function(PathR) {gsub(".R2.fastq.gz", “”, PathR)}))
PathR <- data.frame(lapply(PathR, function(PathR) {gsub(“fastq.gip”, “fastq.gz”, PathR)}))
PathR <- data.frame(lapply(PathR, function(PathR) {gsub("/N/", “/Data/”, PathR)}))

PathR <- PathR[,c(3,1,2)]

Manifest <- rbind(PathF, PathR)

names(Manifest)[names(Manifest)==“sample.id”] <- “sample-id”

names(Manifest)[names(Manifest)==“absolute.filepath”] <- “absolute-filepath”

write_csv(Manifest, “Manifest.csv”)

IMPORTANT!!!
ALL OF THE “” and ‘’ change format to curly types here! =O
Please take care to change them back before use!

For use on single end reads please use this instead of the above (WARNING, still fresh off the press so is likely to have a few issues)

 #!/usr/bin/env Rscript
library(tidyverse)

data_path <- paste (setwd ("Data/"),"Data", sep = "/")
SamplesF <- list.files(path = data_path, pattern = "*.R1.fastq.gz", all.files = FALSE,
       full.names = TRUE, recursive = FALSE,
       ignore.case = FALSE, include.dirs = FALSE, no.. = FALSE)

TabF <- as.data.frame(SamplesF)

PathF <- data.frame(lapply(TabF, function(TabF) {gsub("Data/", "$PWD/N/", TabF)}))
PathF <- data.frame(lapply(PathF, function(PathF) {gsub("fastq.gz", "fastq.gip", PathF)}))

names(PathF)[names(PathF)=="SamplesF"] <- "absolute-filepath" 

PathF['direction']='forward'

PathF['sample-id']= SamplesF

PathF <- data.frame(lapply(PathF, function(PathF) {gsub("Data/", "sample-", PathF)}))
PathF <- data.frame(lapply(PathF, function(PathF) {gsub(".R1.fastq.gz", "", PathF)}))
PathF <- data.frame(lapply(PathF, function(PathF) {gsub("fastq.gip", "fastq.gz", PathF)})) 
PathF <- data.frame(lapply(PathF, function(PathF) {gsub("/N/", "/Data/", PathF)})) 

PathF <- PathF[,c(3,1,2)]

Manifest <- rbind(PathF)

names(Manifest)[names(Manifest)=="sample.id"] <- "sample-id" 

names(Manifest)[names(Manifest)=="absolute.filepath"] <- "absolute-filepath" 

write_csv(Manifest, "Manifest.csv")

```

Hey there @mouldinator

Discourse (the platform this forum is built on) supports a wide variety of formatting options, including code formatting. Simply place your code in a triple-backtick code-fence like this:

```
my code...
```

You can also get syntax highlighting:

```bash
echo $PATH
```

which will render like this:

echo $PATH

Regarding the curly quotes - those might also be coming from the editor you are working with, but if not, the code fences will use programming quotes instead of prose quotes.

2 Likes

Thanks, will use that in the future =)
cheers

Feel free to use it now — you can actually edit your existing posts, that way you can remove your warning about curlies.

The future is now! :dark_sunglasses: :first_quarter_moon_with_face:

1 Like

Whilst I think it is a good idea to make the directory a variable to make it easier to change, I did say you’d need to change it…

@ Micro_Biologist hey there! Unfortunately didn’t do a very good job; I keep getting the absolute filepath pasted onto the sequence ID in the manifest files and qiime tools cant Import it as it dosnt recognise the manifest file type

Hello, you may want to take a look at this plugin which generate metadata and manifest through folder structure : )
https://library.qiime2.org/plugins/qiime2-manifest-metadata-generator/23/