-bash: ./HeatMap.R: cannot execute binary file. Why is this?
2
0
Entering edit mode
5.5 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")
Data <- read.csv("input.txt", sep = "\t", header = TRUE)
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 • 2.9k views
ADD COMMENT
1
Entering edit mode

Running R scripts from command line.

ADD REPLY
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
ADD REPLY
0
Entering edit mode

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

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

You're missing a double quote.

ADD REPLY
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

ADD REPLY
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.

ADD REPLY
1
Entering edit mode

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

ADD REPLY
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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

to be honest I am not sure what you mean.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

it returns this,

-bash: ./HeatMap.R: cannot execute binary file
ADD REPLY
0
Entering edit mode

You ran

./Heatmap.R

Eric asked you to run

file Heatmap.R
ADD REPLY
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.

ADD REPLY
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.

ADD REPLY
0
Entering edit mode

You shouldn't execute an Rscript with bash.

Please follow up on all your previous posts:

If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted.
Upvote|Bookmark|Accept

ADD REPLY
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?

ADD REPLY
0
Entering edit mode
which -a Rscript

/usr/local/bin/Rscript

ADD REPLY
2
Entering edit mode
5.5 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
#colnames(DataMatrix) <- c("male", "female", "juvenile", "egg", "blastula") #Already set by header=TRUE
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
ADD COMMENT
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>'
Calls: read.csv -> read.table -> make.names
In addition: Warning messages:
1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 1 appears to contain embedded nulls
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 2 appears to contain embedded nulls
3: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 3 appears to contain embedded nulls
4: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 4 appears to contain embedded nulls
5: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  line 5 appears to contain embedded nulls
Execution halted
ADD REPLY
0
Entering edit mode

Hi,

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

ADD REPLY
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.

ADD REPLY
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:

101010 Button

ADD REPLY
1
Entering edit mode

If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted.
Upvote|Bookmark|Accept

ADD REPLY
0
Entering edit mode
5.5 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
ADD COMMENT
0
Entering edit mode

Sorry, why is this an answer? Please use comments unless you're answering the top level question.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

why is this an answer?

That does not answer the above question. You should have edited your post and added this info there, not added it as an answer. Please edit and add now, and then delete this answer.

ADD REPLY

Login before adding your answer.

Traffic: 2417 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6