To whom this may concern:
Here is the source code:
GRA_D1<- raster(files[[1]])
//Sets up an empty output raster:
GRA_D1<- writeStart(GRA_D1,filename='GRA_D1.tif', format='GTiff', overwrite=TRUE)
//Write to the raster, for loop:
for(i in 1:dim(GRA_D1)[1]){
//Extract raster values at rows
d.Frame<- matrix(NA,ncol=2,nrow=dim(GRA_D1)[2])
d.Frame[,1]<- getValues(r1[[1]],i)
d.Frame[,2]<- getValues(r1[[2]],i)
w.Frame<- as.data.frame(d.Frame)
names(w.Frame)<- c("D1_pred_disAg","D1_pred_RK")
//Apply the predictive model:
m.pred<-predict(mod.1, w.Frame)
//Write the predictions to the empty TIFF raster
GRA_D1<-writeValues(GRA_D1,m.pred,i)
print(i)}
//Finish writing to the raster
GRA_D1<- writeStop(GRA_D1)
I am attempting to write output to an empty TIFF raster, but I keep receiving the following error message:
#Error in .local(.Object, ...) :
`general_file_path\GRA_D1.tif' does not exist in the file system,
and is not recognised as a supported dataset name.
I wonder if this is related to misusing functions in either the RGDAL or RASTER package.
Could someone please assist me?
Thanks in advance for your generosity.
Cheers,
AD
Super simple fix. Cannot believe that it is this simple and that it took me this long, but here is the answer:
"rgdal" and/or "GTiff" files don't like the use of underscores in their dataset names.
When running the code with "GRAD1.tif" (instead of "GRA_D1.tif"), all works well.
You really should not be doing any of this, I think, as you could do:
p <- predict(r1, mod.1, filename='GRA_D1.tif')
(and that filename works just fine)
Related
I'm trying to read an mlc file (output from CODEML program) using the read.codeml_mlc function from the treeio package, as follows:
library(ggtree)
library(treeio)
tree <- read.codeml_mlc(mlc_file)
However, I'm getting the following error:
Error in strsplit(., split = "[[:space:]]") :
non character argument
Does anyone have an idea of what could be wrong? This is an ordinary mlc output from PAML from a free ratio branch model, I have not modified or altered it. However, the error seems to be related to my file, because I have tried running the example from the tutorial (reading the mlc file provided with the package) and it works fine.
Put it some other way: Where does the strsplit function come about when reading the mlc file and what part exactly of the file is it refering to? Maybe knowing that will help solve my problem.
Thanks in advance for any help that could be provided!!
I tried to use the RImageJROI package from David C Sterratt to transfer multiple ROIs into R and convert them to Spatstat.
This is a minimal example of my R-code
library(RImageJROI)
ROI = read.ijzip("path/ROI.zip")
spat.ROI = ij2spatstat(ROI)
Reading the zip-file works well but when I run the converting command I get the following error:
Error in conv.fun(k, window = window, unitname = unitname, scale =
scale, : object 'out' not found
Attached there is a file for creating a ROI.zip -file which causes the error after processing it in ImageJ with:
run("Analyze Particles...", "add");
roiManager("Save", "Path\\Roi.zip");
Is there a way to get RImageJROI working, am I missing something obvious, or does anyone know another solution for my project?
You can use Bio7 for that with has special methods to transfer different ImageJ ROI's and image data to R.
Some methods where especially designed for spatstat after a great spatstat tutorial on the R conference in 2015.
Here a link to some ImageJ spatstat notes and simple scripts:
http://bio7.org/?p=2618
https://github.com/Bio7/Bio7_Workshop
Here some video tutorials to transfer ROI data:
3D Point Pattern:
https://youtu.be/DmfSASgJa_g
Line Segments:
https://youtu.be/EPan7kibYpo
Polygons:
https://youtu.be/bS_2ejOt7Tg
Point Patterns:
https://youtu.be/7t5V2o8jFJw
Particle Measurments:
https://youtu.be/7t5V2o8jFJw
Georeferenced Polygons (which can be converted to spatstat objects):
https://youtu.be/P2NflfBB2Tg
I got the same error message. I found this to work after looking inside the ij2spatstat function.
library(RImageJROI)
library(spatstat)
roi <- read.ijroi("RoiSet/0071-0081.roi") # path to single ROI
poly <- list(x = roi$coords[,2], y = roi$coords[,1])
out <- owin(poly = poly)
plot(out)
You can put this inside a loop to transform every ROI in a directory.
I try to load a .mat file using the R.matlab library. When I run:
x <- readMat("MPL.mat")
I get this error however.
Error in mat5ReadTag(this) :
Unknown data type. Not in range [1,19]: 18569
In addition: Warning message:
In readMat5Header(this, firstFourBytes = firstFourBytes) :
Unknown MAT version tag: 512. Will assume version 5.
Anybody who experienced this and has a way to deal with this?
Im familiar with this post: R.matlab/readMat : Error in readTag(this) but alternatives ways didnt work for me...
The problem is related to how is saved your "MPL.mat". If you save by default in MATLAB, it probably won't work using R.matlab in R.
When I saved my .mat object in '-v7' or '-v6' i did not have problems, but the R.matlab documentation suggest to save in '-v6' (Pag.25 in R.matlab package). For example, I saved 2 matrices (A and B) in 'MPL.mat'.
save('MPL.mat','A', 'B', '-v7')
I could read in R:
require(R.matlab)
data <- readMat("MPL.mat")
View(data$A)
View(data$B)
I'm trying to import a SRTM dataset into R. I've downloaded the data in a tif file however am having trouble reading it in "R".
Ive tried using the following code:
t = readTIFF("srtm_56_06/srtm_56_06.tif", as.is=TRUE)
load('srtm_56_06/srtm_56_06.tif')
read_file<-as.matrix(raster("srtm_56_06/srtm_56_06.tif")
However I am still getting error messages:
load('srtm_56_06/srtm_56_06.tif')
# Error: bad restore file magic number (file may be corrupted) -- no data loaded
# In addition: Warning message:
# file ‘srtm_56_06.tif’ has magic number 'II*'
# Use of save versions prior to 2 is deprecated
library(raster)
t = readTIFF("srtm_56_06/srtm_56_06.tif", as.is=TRUE)
# Error: could not find function "readTIFF"
read_file<-as.matrix(raster("srtm_56_06/srtm_56_06.tif") + min(read_file)
# Error: unexpected symbol in:
# "read_file<-as.matrix(raster("srtm_56_06/srtm_56_06.tif")
# min"
Can anyone help me with the commands to import this data. I'm a novice at "R" and a little lost.
Just read it with raster, but note you depend on rgdal being installed as well to read a .tif.
library(raster)
library(rgdal)
r <- raster("srtm_56_06/srtm_56_06.tif")
If that works, try
plot(r)
r
If it's really a "TIFF" then that should be fine, if it's really a GeoTIFF then you'll have a sensible map as well. (If it's something else that GDAL can read you might get a good result anyway, remember the extension of a file is not a reliable indicator of its contents).
The SRTM clue suggests that this is a single band DEM file from the tiled global SRTM data set. If it's somehow a "multi-band image" then you could read that with brick and plot with plotRGB (but I really doubt that is the case here). Note that there is a native binary format for SRTM that raster/rgdal could read as well but either they distributed .tif as well or someone else converted it.
There are a number of misconceptions in your code:
load is for a particular file type created from R (not these .tifs)
readTIFF is not in package raster
read_file would be a sensible matrix, if you have rgdal installed (which raster must use to load a .tif), but why throw away the spatial metadata?
I've searched the web for this without much luck. More or less you always get to the example from the VariantAnnotation Package. And since this example works fine on my computer I have no idea why the VCF I created does not.
The problem: I want to determine the number and location of SNPs in selected genes. I have a large VCF file (over 5GB) that has info on all SNPs on all chromosomes for several mice strains. Obviously my computer freezes if I try to do anything on the whole genome scale, so I first determined genomic locations of genes of interest on chromosome 1. I then used the VariantAnnotation Package to get only the data relating to my genes of interest out of the VCF file:
library(VariantAnnotation)
param<-ScanVcfParam(
info=c("AC1","AF1","DP","DP4","INDEL","MDV","MQ","MSD","PV0","PV1","PV2","PV3","PV4","QD"),
geno=c("DP","GL","GQ","GT","PL","SP","FI"),
samples=strain,
fixed="FILTER",
which=gnrng
)
The code above is taken out of a function I wrote which takes strain as an argument. gnrng refers to a GRanges object containing genomic locations of my genes of interest.
vcf<-readVcf(file, "mm10",param)
This works fine and I get my vcf (dim: 21783 1) but when I try to save it won't work
file.vcf<-tempfile()
writeVcf(vcf, file.vcf)
Error in .pasteCollapse(ALT, ",") : 'x' must be a CharacterList
I even tried in parallel, doing the example from the package first and then substituting for my VCF file:
#This is the example:
out1.vcf<-tempfile()
in1<-readVcf(fl,"hg19")
writeVcf(in1,out1.vcf)
This works just fine, but if I only substitute in1 for my vcf I get the same error.
I hope I made myself clear... And any help will be greatly appreciated!! Thanks in advance!
Thanks for reporting this bug. The problem is fixed in version 1.9.47 (devel branch). The fix will be available in the release branch after April 14.
The problem was that you selectively imported 'FILTER' from the 'fixed' field but not 'ALT'. writeVcf() was throwing an error because there was no ALT value to write out. If you don't have access to the version with the fix, a work around would be to import the ALT field.
ScanVcfParam(fixed = c("ALT", "FILTER"))
You can see what values were imorted with the fixed() accessor:
fixed(vcf)
Please report and bugs or problems on the Bioconductor mailing list Martin referenced. More Bioc users will see the question and you'll get help more quickly.
Valerie
Here's a reproducible example
library(VariantAnnotation)
fl <- system.file("extdata", "chr22.vcf.gz", package="VariantAnnotation")
param <- ScanVcfParam(fixed="FILTER")
writeVcf(readVcf(fl, "hg19", param=param), tempfile())
## Error in .pasteCollapse(ALT, ",") : 'x' must be a CharacterList
The problem seems to be that writeVcf expects the object to have an 'ALT' field, so
param <- ScanVcfParam(fixed="ALT")
writeVcf(readVcf(fl, "hg19", param=param), tempfile())
succeeds.