0

I'm trying to get an R-script to work, the instructions on how I set up/ installed the packages can be found here https://forum.qiime2.org/t/automatic-manifest-maker-in-r/2921 If you'd like to try the script please add

#!/usr/bin/env Rscript

to the first line of the script and de/reactivate R-Env (Credit; Duckmayr) syntax errors (in R-script)

The new issue is that it now returns a new error;

(R-Env) qiime2@qiime2core2018-8:~/Desktop/MACE_DEMUX_FASTQs/barcode08$ 
~/Taxonomy.R
── Attaching packages ─────────────────────────────────────── tidyverse 
1.2.1 ──
✔ ggplot2 2.2.1     ✔ purrr   0.2.4
✔ tibble  1.4.2     ✔ dplyr   0.7.5
✔ tidyr   0.8.1     ✔ stringr 1.3.1
✔ readr   1.1.1     ✔ forcats 0.3.0
── Conflicts ──────────────────────────────────────────             
tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
Error in `[<-.data.frame`(`*tmp*`, "direction", value = "forward") : 
replacement has 1 row, data has 0
Calls: [<- -> [<-.data.frame
Execution halted

I have never done anything using R before so please forgive me if this is a dumb question.

a little context; This is being performed in a conda environment on a vm ubuntu machine and is supposed to create a file called Manifest.csv which contains metadata from the .fastq files in the current directory. I take no credit for the script, it is open access and I did not write it.

Gus Bishop
  • 23
  • 6
  • What is the output of the terminal command `find ~ -maxdepth 2 -name "*.R1.fastq.gz"` – duckmayr Sep 25 '18 at 11:31
  • There is none =/ – Gus Bishop Sep 25 '18 at 11:46
  • (1) What directory are your `.R1.fastq.gz` files stored in? (2) Where are you calling the R script from? (i.e., what is the output of the terminal command `pwd` if you call it *right* before you call your R script). I think the issue might be that your R script doesn't find any `.R1.fastq.gz` files, so `TabF` and `PathF` don't have any rows, which would cause something like `PathF['direction']='forward'` to create the error you get. – duckmayr Sep 25 '18 at 11:57
  • 1)`fastq.gz` are stored in `~/Desktop/MACE_DEMUX_FASTQs/barcode08` 2) the R script is being called from the root directory using `~/Taxonomy.R` – Gus Bishop Sep 25 '18 at 12:01
  • I have answered maybe half a dozen other questions on this site that went "I use conda and my R is broken" with "do not mix conda and R". CRAN has pretty stringent quality control, and "stuff works". Conda adds another layer to the mix, and that seems to (at least "sometimes") stir things up for the worse. – Dirk Eddelbuettel Sep 25 '18 at 12:12

1 Answers1

0

Your error comes because the script you've used assumes your .R1.fastq.gz are in a Data/ subdirectory of your working directory, but as determined in the comments, that is not the case. This causes TabF and PathF to not have any rows, which causes PathF['direction']='forward' to create the error you get.

The fix is to change

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

to

data_path <- paste("~/Desktop/MACE_DEMUX_FASTQs/barcode08", "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)

as well as changing

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

to

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)

and make sure your .R1.fastq.gz and .R2.fastq.gz files are in a Data/ subdirectory of ~/Desktop/MACE_DEMUX_FASTQs/barcode08.

duckmayr
  • 16,303
  • 3
  • 35
  • 53
  • Thanks! I made the amendments as suggested and then made a directory within the directory `/barcode08` and moved all the `.gz` into it, unfortunately trying to run the script returns the same error, regardless of which directory I'm in when I try to run it – Gus Bishop Sep 25 '18 at 12:27
  • @GusBishop Hmm... Just for clarification, I want to make sure: Do you mean the *exact* same error (`Error in \`[<-.data.frame\`(\`*tmp*\`, "direction", value = "forward")`)? If so, can you insert the line `nrow(TabF)` after the line `TabF <- as.data.frame(SamplesF)` and report the output after `✖ dplyr::lag() masks stats::lag()` but before `Error in \`[<-.data.frame\`(\`*tmp*\`, "direction", value = "forward") : `? – duckmayr Sep 25 '18 at 12:32
  • ` ── Attaching packages tidyverse 1.2.1 ── ✔ ggplot2 2.2.1 ✔ purrr 0.2.4 ✔ tibble 1.4.2 ✔ dplyr 0.7.5 ✔ tidyr 0.8.1 ✔ stringr 1.3.1 ✔ readr 1.1.1 ✔ forcats 0.3.0 ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ── ✖ dplyr::filter() masks stats::filter() ✖ dplyr::lag() masks stats::lag() Error in `[<-.data.frame`(`*tmp*`, "direction", value = "reverse") : replacement has 1 row, data has 0 Calls: [<- -> [<-.data.frame Execution halted (R-Env) qiime2@qiime2core2018-8:~/Desktop/MACE_DEMUX_FASTQs/barcode08$ ` – Gus Bishop Sep 25 '18 at 12:36
  • the above is the current error (not with most recent ammendments) Just posting for the benifit of future readers – Gus Bishop Sep 25 '18 at 12:37
  • and now after the amendments (I'm only posting the error part of the output from now on here) `[1] 4 Error in `[<-.data.frame`(`*tmp*`, "direction", value = "reverse") : replacement has 1 row, data has 0 Calls: [<- -> [<-.data.frame` – Gus Bishop Sep 25 '18 at 12:38
  • @GusBishop I see the issue; there was another similar command later in the script. Please see the edited answer. – duckmayr Sep 25 '18 at 12:43
  • `✖ dplyr::filter() masks stats::filter() ✖ dplyr::lag() masks stats::lag() [1] 4 Error in `[<-.data.frame`(`*tmp*`, "direction", value = "reverse") : replacement has 1 row, data has 0 Calls: [<- -> [<-.data.frame Execution halted` – Gus Bishop Sep 25 '18 at 12:48
  • I made the ammendments as per your instructions and also added `nrow(TabF)` in the line below "TabF" unfortunately still getting the above error (Also, thank you so much for all your help @duckmayr!!!!!!!!!) – Gus Bishop Sep 25 '18 at 12:50
  • This may be due to the type of data I am using, I have only got 1D reads.. ie. my data is all forward, the script seems to be looking for their partner reads. I'll try with some 2D example data to see if this is the case – Gus Bishop Sep 25 '18 at 13:08
  • IT WORKED!!!! @duckmayr thanks =D It dosn't work with my data but it does with the example data, therefore it is a question of having forward and reverse-complimentary files unfortunately. I'll post as to how to avoid this in a new question – Gus Bishop Sep 25 '18 at 13:19