Thank you! As I said above I think there might be a problem as I ran salmon for multiple files together and have only one quant.sf. Now I am trying to run an array to produce different quant.sf files for each pair of files.
Salmon to tximport error
Hello,
I have salmon output as a directory with multiple files including quant.sf. I am trying to import it to R using tximport:
setwd("/path/quant/")
dir <- dir(paste0(path.package("tximportData"), "/path/quant/"), full.names = TRUE)
list.files()
samples <- read.csv("path/Table.csv", sep=";", header = TRUE)
samples
files <- file.path(dir, "salmon", samples$Run, "quant.sf")
names(files) <- paste0("samples", 1:100)
But it gives an error:
Error in names(files) <- paste0("samples") :
'names' attribute [100] must be the same length as the vector [0]
However, the individual files, Table.csv and quant.sf both have 100 observations information. Thank you!
• 5,883 views
•
link
1 answer
I always do it like this:
1) Put all the directories that salmon produced (the ones that contain the quant.sf files) into a directory.
I personally always call this salmons.
2) Once you moved all these directories into the salmons directory you enter this directory from within R:
setwd("path/to/salmons/")
3) You list the quant.sf files, give each file a name and then run tximport:
my.files <- list.files(list.dirs(path = ".", full.names = TRUE, recursive = FALSE), pattern = "quant.sf", full.names = TRUE)
> [1] "./B_rep1_salmon/quant.sf" "./B_rep2_salmon/quant.sf"
## You give the samples a name, I always use the directory name:
names(my.files) <- sapply(strsplit(my.files, split="\\/"), function(x)x[2])
> head(my.files, 6)
B_rep1_salmon B_rep2_salmon
"./B_rep1_salmon/quant.sf" "./B_rep2_salmon/quant.sf"
## Now run tximport. Done.
txi <- tximport(files = my.files, type = "salmon", tx2gene = tx2gene)
• 0 views
•
link
• 0 views
•
link
I finally got
>all(file.exists(my.files))
TRUE
Now I am trying to create tx2gene using:
TxDb <- makeTxDbFromGFF(file = "/path/gene_models.gff")
k <- keys(TxDb, keytype = "TXNAME")
tx2gene <- select(TxDb, k, "GENEID", "TXNAME")
head(tx2gene)
But I got error:
> tx2gene <- select(TxDb, k, "GENEID", "TXNAME")
Error in UseMethod("select_") :
no applicable method for 'select_' applied to an object of class "c('TxDb', 'AnnotationDb', 'envRefClass', '.environment', 'refClass', 'environment', 'refObject', 'AssayData')"
• 0 views
•
link
To get last directory name:
my.files <- c("./B_rep1_salmon/quant.sf", "./B_rep2_salmon/quant.sf")
basename(dirname(my.files))
# [1] "B_rep1_salmon" "B_rep2_salmon"
• 0 views
•
link
Log in to answer this question.
The error implies that the length of
filesis not equal to 100. So, please check the contents of thefilesvariable.You've got some weird things goin on in this snippet:
/path/quanteven exists?dirfunction with the content of its result;separated?filesvector is empty, pay attention that you print the output oflist.files()but never use this output, make sure you don't assume it's likedirThank you! 1. I took out setwd. 2. I changed the output file name. 3. Yes. 4.
filesvector actually shows the file and run names. But I get:For Salmon, you basically just need the following components (I have taken this from one of my previous datasets):
Thank you! I have this:
But I am still getting:
I am not what is going wrong.
Do these files exist under
getwd()?getwd()shows thedirname wherequant.sfis located.All that you need to use, from any directory, is
list.files(). Once you havelist.files()listing the relative paths of your quant.sf files, then everything else should be easy.Take a look at this example, where I start at my command prompt, and then move to R:
BASH
R
Okay, so in the first step after setting the path to directory containing
quant.sf,list.files()just gives the names of the folders in that directories with one folder havingquant.sffile.Do you know how Salmon output looks like? Each folder is a library with a
quant.sffile. You should list the files in the head directory (that contains all the Salmon results) and work from there. Make sure you don't mix dirs. Take your time, you'll figure it out eventually.Okay. I ran salmon for multiple files together and have one quant.sf. Do I need to run it individually for each paired end fastq file.
No, you should run it separately for each sample, it may have a few files if it was sequenced in different lanes.
Side note: use
read.csv2when we have";"as a separator.