I am using vcftools in an .Rmd file to plot my basic vcf stats. I had this code working for a while, but yesterday it decided to stop and give me an error.
Thanks in advance!
The code I ran and the error that I received is below.
prefix <- "./wss_all_data/all.snps"
plot.vcf.stats(prefix
`Error in file(file, "rt") : cannot open the connection
4.file(file, "rt")
3.read.table(file = file, header = header, sep = sep, quote = quote,
dec = dec, fill = fill, comment.char = comment.char, ...)
2.read.delim(paste(prfx, ".imiss", sep = ""), sep = "t", header = TRUE)
1.plot.vcf.stats(prefix)`
I saw another question about this, but I tried that answer and it did not solve my problem.
Interestingly, when I run it from another .Rmd file (with all the same commands), it works just fine. I have the .Rmd file in the directory with all of the data.
Based on some trouble shooting, I also tried
{r, fig.width=8, fig.height=6} wss_all_data <- "wss_all_data" imiss_file <- file.path('wss_all_data/all.snps.imiss') ldepth_mean_file <- file.path(wss_all_data, "all.snps.ldepth.mean") idepth_file <- file.path(wss_all_data, "all.snps.idepth") lmiss_file <- file.path(wss_all_data, "all.snps.lmiss")
Now plot.
{r} #Function to read and plot .imiss file plot_imiss <- function(file) { data <- read.table(file, header = TRUE, sep = "t", stringsAsFactors = FALSE) ggplot(data, aes(x = F_MISS)) + geom_histogram(binwidth = 0.01, fill = "blue", color = "black") + theme_minimal() + labs(title = "Missing Data Proportion", x = "F_MISS", y = "Count") }
#Function to read and plot .ldepth.mean file
plot_ldepth_mean <- function(file) {
data <- read.table(file, header = TRUE, sep = "t", stringsAsFactors = FALSE)
ggplot(data, aes(x = MEAN_DEPTH)) +
geom_histogram(binwidth = 1, fill = "green", color = "black") +
theme_minimal() +
labs(title = "Site Mean Depth",
x = "MEAN_DEPTH",
y = "Count")
}
#Function to read and plot .idepth file
plot_idepth <- function(file) {
data <- read.table(file, header = TRUE, sep = "t", stringsAsFactors = FALSE)
ggplot(data, aes(x = MEAN_DEPTH)) +
geom_histogram(binwidth = 1, fill = "orange", color = "black") +
theme_minimal() +
labs(title = "Individual Mean Depth",
x = "MEAN_DEPTH",
y = "Count")
}
#Function to read and plot .lmiss file
plot_lmiss <- function(file) {
data <- read.table(file, header = TRUE, sep = "t", stringsAsFactors = FALSE)
ggplot(data, aes(x = F_MISS)) +
geom_histogram(binwidth = 0.01, fill = "purple", color = "black") +
theme_minimal() +
labs(title = "Site Missingness",
x = "F_MISS",
y = "Count")
}
#Generate and display the plots
print(plot_imiss(imiss_file))
print(plot_ldepth_mean(ldepth_mean_file))
print(plot_idepth(idepth_file))
print(plot_lmiss(lmiss_file))`
And received this error: Warning: cannot open file 'wss_all_data/all.snps.imiss': No such file or directory Error in file(file, "rt") : cannot open the connection
user25532585 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.