-bash: ./HeatMap.R: cannot execute binary file. Why is this?
2
0
Entering edit mode
3.3 years ago
jaqx008 ▴ 110

Hello everyone, I am trying to run an R script to generate a heat-map but I keep getting the following error. I have no idea what is wrong with my input file. My input looks like this:

      male   female   juvenile   egg   blastula
Aub  13.3   34.1     2323       321   3231
piwi   23     34        34           54      534
Ago  35     65         34           34      56
Ago2 0       0           0            0         0


-bash: ./HeatMap.R: cannot execute binary file

my R script look like this.

#!/usr/bin/env Rscript
library("gplots")
DataMatrix <- data.matrix(Data)
rownames(DataMatrix) <- c("Aub", "piwi", "Ago", "Ago2")
colnames(DataMatrix) <- c("male", "female", "juvenile", "egg", "blastula")
png('ZscorePlot.png')
DataMap <- heatmap.2(DataMatrix, trace="none", dendrogram ='none', Rowv = FALSE, Colv = FALSE, col = colorRamps::matlab.like2, key=TRUE, keysize=1.0, xlab = "Stage in Development", ylab = "RNAifactor")
dev.off()


Is there something wrong? by the way, this is not my original data, just a sample to show you how it looks like. thanks.

Heatmapscript mapping Rnaseq Rpm • 1.5k views
1
Entering edit mode

Running R scripts from command line.

0
Entering edit mode

I tried to execute the commands one at a time on command line and upon reaching

> rownames(DataMatrix) <- c("Bfl-Piwi-like1","Bfl-Piwi-like3","Bfl-Piwi-like2","Bfl-Piwi-like5","Bfl-Piwi-like4","Bfl-Ago1","Bfl-Ago-like","Bfl-Rdrp4","Bfl-Rdrp1","Bfl-Rdrp2","Bfl-Rdrp3","Bfl-Rdrp5","Bfl-Rdrp6","Bfl-Dro","Bfl-Dcr")


it gave the error

Error in dimnames(x) <- dn :
length of 'dimnames' [1] not equal to array extent

0
Entering edit mode

Your R script has errors then. Please fix them before trying to execute the script from the command line.

0
Entering edit mode
rownames(DataMatrix) <- c("Aub", "piwi", Ago")
----------------------------------------^


You're missing a double quote.

0
Entering edit mode

Thats me typing on here. its all good in my R script. I corrected that on the post. In my script its all good. But error persists

0
Entering edit mode

Why is your R script binary? Have you tried Rscripts myscripts.R? The cannot execute binary file typically has something with incompatible architectures.

1
Entering edit mode

I think it should be Rscript file.R, not Rscripts.

0
Entering edit mode
Rscript Heatmap.R


gave this

Error: unexpected input in "book" Execution halted

sorry for late response, I am limited to ew posts

0
Entering edit mode

Of course. Now everybody knows I hardly run any R script. :D

0
Entering edit mode

to be honest I am not sure what you mean.

0
Entering edit mode

What does it return with the command file HeatMap.R?

0
Entering edit mode

it returns this,

-bash: ./HeatMap.R: cannot execute binary file

0
Entering edit mode

You ran

./Heatmap.R


file Heatmap.R

0
Entering edit mode

file Heatmap.R gave the following and didnt generate anything in folder

HeatMap.R: data

I apologies for late response. I am limited to few post per certain hours.

0
Entering edit mode

The file utility tells you what kind of file Heatmap.R is, it does nothing else - that's expected. Think of it as a sanity check on the file. It is strange that you get data.

0
Entering edit mode

You shouldn't execute an Rscript with bash.

0
Entering edit mode

You need to run your file as:

\$ Rscript HeatMap.R


You cannot run Rscripts with the R binary or with bash. Your shebang line should be taking care of this though.

What do you get for which -a Rscript?

0
Entering edit mode
which -a Rscript


/usr/local/bin/Rscript

2
Entering edit mode
3.3 years ago

Column names are 5 and the number of columns are 6. The issue can be addressed by setting the first column as row names.

#!/usr/bin/env Rscript
library("gplots")
Data <- read.csv("input.tsv", sep = "\t", header = TRUE, row.names = 1) #first col as rownames
DataMatrix <- data.matrix(Data)
#rownames(DataMatrix) <- c("Aub", "piwi", "Ago", "Ago2") #Already set by row.names = 1
png('ZscorePlot.png')
DataMap <- heatmap.2(DataMatrix, trace="none", dendrogram ='none', Rowv = FALSE, Colv = FALSE, col = colorRamps::matlab.like2, key=TRUE, keysize=1.0, xlab = "Stage in Development", ylab = "RNAifactor")
dev.off()


Run using the Rscript command also make sure the data table is properly formatted.

input.tsv

        male    female  juvenile        egg     blastula
Aub     13.3    34.1    2323    321     3231
piwi    23      34      34      54      534
Ago     35      65      34      34      56
Ago2    0       0       0       0       0

0
Entering edit mode

this is the error after i run it

Attaching package: ‘gplots’

The following object is masked from ‘package:stats’:

lowess

Error in make.names(col.names, unique = TRUE) :
invalid multibyte string at '<fe><ff>'
line 1 appears to contain embedded nulls
line 2 appears to contain embedded nulls
line 3 appears to contain embedded nulls
line 4 appears to contain embedded nulls
line 5 appears to contain embedded nulls
Execution halted

0
Entering edit mode

Hi,

I've updated the code there is no need to set rownames and colnames separately.

0
Entering edit mode

I realized my Text file had a tab in the first row. removing the tab makes the code run without a problem. Thanks for all your help. I appreciate it.

1
Entering edit mode

I added code markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

1
Entering edit mode

0
Entering edit mode
3.3 years ago
jaqx008 ▴ 110

new text file that made the code work looks like this

name  male    female  juvenile        egg     blastula
Aub     13.3    34.1    2323    321     3231
piwi    23      34      34      54      534
Ago     35      65      34      34      56
Ago2    0       0       0       0       0

0
Entering edit mode

0
Entering edit mode

I added correction to my initial text file. tab replaced with name.

0
Entering edit mode