Execution halted error in R - r

I run hicpipe tools and it returns this error during execution. Its error was:
Rsge temp files: tmp/Rsge.test_cluster.binned.*
Error in if (trace) cat("Running locally \n") :
argument is of length zero
Calls: compute.total.counts -> model.predict.split -> sge.parRapply
Execution halted
Error: error in total_expected_counts_wrapper.r
Execution halted
make[1]: *** [/home/dashti/hicpipe/output/test_cluster/test_cluster.nm]
Error 1
make[1]: Leaving directory `/home/dashti/hicpipe'
make: *** [all] Error 1
It was run a Rscript code in below:
Rscript R/total_expected_counts_wrapper.r /home/dashti/hicpipe/output/test_cluster/test_cluster /home/dashti/hicpipe/models/map_len_gc.mdl trans 1e+06 0 200
Code of total_expected_counts_wrapper.r is :
options(warn=1)
# get script name
all.args = commandArgs(F)
fn.arg = "--file="
script.name = sub(fn.arg, "", all.args[grep(fn.arg, all.args)])
args = commandArgs(T)
if (length(args) == 1) {
cat(sprintf("usage: %s <input prefix> <model file> <filter> <cis.threshold> <use cluster> <max jobs on cluster>\n",
script.name))
q(status=1)
}
ifn.prefix = args[1]
model.ifn = args[2]
filter = args[3]
cis.threshold = as.numeric(args[4])
cluster = (args[5] == "1")
max.njobs = as.numeric(args[6])
mtable = read.delim(model.ifn)
mfields = mtable$field
maxvals = mtable$size
if (cluster) {
cat("Using Sun Grid Engine cluster\n")
} else {
cat("Not using Sun Grid Engine cluster, running sequentially on local machine\n")
}
source("R/model_predict.r")
compute.total.counts(prefix=ifn.prefix, cluster=cluster, max.njobs=max.njobs, ofields=mfields, max.vals=maxvals, filter=filter, cis.threshold=cis.threshold)
q(status=0)
What should I do? I see other .R files but I cannot find any trace variable in them. I send an E-mail to authors but I do not receive any response.

source("R/model_predict.r")
In model_predict.r, Rsge library is loaded
173 library(Rsge)
174 sge.options(sge.save.global=F)
175 sge.prefix = paste("tmp/Rsge.", get.short.fn(fends.fn), ".", sep="")
176 cat(sprintf("Rsge temp files: %s*\n", sge.prefix))
177 sge.options(sge.file.prefix=sge.prefix)
178
179 result = sge.parRapply(ranges, model.predict, lib.dir=lib.dir,
180 njobs=njobs, join.method=c, cluster=cluster,
181 fends.fn=fends.fn, log.dir=log.dir,
182 prior=prior, mfields=mfields, mfields.maxvals=mfields.maxvals, mfields.fns=mfields.fns,
183 filter=filter, cis.threshold=cis.threshold, ofields.x=ofields.x, ofields.y=ofields.y,
184 function.savelist=c("get.short.fn", "get.ofield.args"))
185 if (class(result) == "list" && class(result[[1]]) == "try-error")
186 return (-1)
and it seems that Rsge does not work properly.
I workarounded by editing Rsge/sge.parApply.R code
(set value of variables equal to Rsge/sge.optionR)
and reinstalling Rsge.
1
2 # $Id: sge.parRapply.R,v 1.2 2006/12/15 15:21:23 kuhna03 Exp $
3
4 sge.apply <- function(X, MARGIN, FUN, ...,
5 join.method=cbind,
6 njobs,
7 batch.size=options('sge.block.size'),
8 packages=NULL,
9 global.savelist=NULL,
10 function.savelist=NULL,
11 cluster=options('sge.use.cluster'),
12 #trace=options('sge.trace'),
13 trace=TRUE,
14 #debug=options('sge.debug'),
15 debug=FALSE,
16 file.prefix=options('sge.file.prefix')
17 ) {

Related

Jupyter script with images for standalone

New to python created a very simple script but seem to be running into issues with images.
I want to take this script and create a standalone.
However when I did it originally without tkinter or imagetk the file would open and close immediately so I tried this.
You can see the error messages I get below the code.
> <sub>`import tkinter as tk from PIL import Image, ImageTk
>
> while True:
> name = input("\nWhat is your name? ")
>
> print(f'\nNice to meet you {name}')
>
> age = input("\nHow old are you? ")
> age = int(age)
> if age >= 40:
> # Open the "old" image
> image = Image.open(r'old.jpg')
> else:
> # Open the "young" image
> image = Image.open(r'young.jpg')
>
> # Convert the image to a PhotoImage object
> photo_image = ImageTk.PhotoImage(image)
>
> # Create a Tkinter window
> root = tk.Tk()
>
> # Create a label and set the image as its background
> label = tk.Label(root, image=photo_image)
> label.pack()
>
> # Run the Tkinter event loop
> root.mainloop()
>
> exit_prompt = input("\nEnter 'exit' to close the script, or press Enter to continue: ")
> if exit_prompt == "exit":
> break
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9860\2051054611.py in <module>
17
18 # Convert the image to a PhotoImage object
---> 19 photo_image = ImageTk.PhotoImage(image)
20
21 # Create a Tkinter window
~\anaconda3\lib\site-packages\PIL\ImageTk.py in __init__(self, image, size, **kw)
138 self.__mode = mode
139 self.__size = size
--> 140 self.__photo = tkinter.PhotoImage(**kw)
141 self.tk = self.__photo.tk
142 if image:
~\anaconda3\lib\tkinter\__init__.py in __init__(self, name, cnf, master, **kw)
4062 Valid resource names: data, format, file, gamma, height, palette,
4063 width."""
-> 4064 Image.__init__(self, 'photo', name, cnf, master, **kw)
4065
4066 def blank(self):
~\anaconda3\lib\tkinter\__init__.py in __init__(self, imgtype, name, cnf, master, **kw)
3995 self.name = None
3996 if not master:
-> 3997 master = _get_default_root('create image')
3998 self.tk = getattr(master, 'tk', master)
3999 if not name:
~\anaconda3\lib\tkinter\__init__.py in _get_default_root(what)
295 if not _default_root:
296 if what:
--> 297 raise RuntimeError(f"Too early to {what}: no default root window")
298 root = Tk()
299 assert _default_root is root
RuntimeError: Too early to create image: no defa
ult root window`
I think you only need to call image.show() after image is opened if you want to show it.
from PIL import Image
while True:
name = input("\nWhat is your name? ")
print(f'\nNice to meet you {name}')
age = input("\nHow old are you? ")
age = int(age)
if age >= 40:
# Open the "old" image
image = Image.open(r'old.jpg')
else:
# Open the "young" image
image = Image.open(r'young.jpg')
image.show()
Once that issue was fixed I was getting the following error:
--------------------------------------------------------------------------- TclError Traceback (most recent call
last) ~\AppData\Local\Temp\ipykernel_11772\4142766009.py in
26
27 # Create a label and set the image as its background
---> 28 label = tk.Label(root, image=photo_image)
29 label.image = photo_image # Keep a reference to the PhotoImage object
30 label.pack()
~\anaconda3\lib\tkinter_init_.py in init(self, master, cnf,
**kw) 3146 3147 """
-> 3148 Widget.init(self, master, 'label', cnf, kw) 3149 3150
~\anaconda3\lib\tkinter_init_.py in init(self, master,
widgetName, cnf, kw, extra) 2570 for k, v in classes:
2571 del cnf[k]
-> 2572 self.tk.call( 2573 (widgetName, self._w) + extra + self._options(cnf)) 2574 for k, v in
classes:
TclError: image "pyimage28" doesn't exist
I tried fixing it by storing the image:
import tkinter as tk from tkinter import PhotoImage from PIL import
Image, ImageTk
while True:
name = input("\nWhat is your name? ")
print(f'\nNice to meet you {name}')
age = input("\nHow old are you? ")
age = int(age)
if age >= 40:
# Open the "old" image
image = Image.open(r'old.jpg')
else:
# Open the "young" image
image = Image.open(r'young.jpg')
# Convert the image to a PhotoImage object
photo_image = PhotoImage(image)
# Create a Tkinter window
root = tk.Tk()
# Create a label and set the image as its background
label = tk.Label(root, image=photo_image)
label.image = photo_image # Keep a reference to the PhotoImage object
label.pack()
# Run the Tkinter event loop
root.mainloop()
exit_prompt = input("\nEnter 'exit' to close the script, or press Enter to continue: ")
if exit_prompt == "exit":
break

Geting error Caused by: com.databricks.NotebookExecutionException: FAILED

I am trying to run the below notebook through databricks but getting the below error. I have tried to update the notebook timeout and the retry mechanism but still no luck yet.
NotebookData("/Users/mynotebook",9900, retry=3)
]
res = parallelNotebooks(notebooks, 2)
result = [f.result(timeout=9900) for f in res] # This is a blocking call.
print(result)
Can someone please help me to sort out this issue? Thanks
%python
from concurrent.futures import ThreadPoolExecutor
class NotebookData:
def __init__(self, path, timeout, parameters=None, retry=0):
self.path = path
self.timeout = timeout
self.parameters = parameters
self.retry = retry
def submitNotebook(notebook):
print("Running notebook %s" % notebook.path)
try:
if (notebook.parameters):
return dbutils.notebook.run(notebook.path, notebook.timeout, notebook.parameters)
else:
return dbutils.notebook.run(notebook.path, notebook.timeout)
except Exception:
if notebook.retry < 1:
raise
print("Retrying notebook %s" % notebook.path)
notebook.retry = notebook.retry - 1
submitNotebook(notebook)
def parallelNotebooks(notebooks, numInParallel):
# This code limits the number of parallel notebooks.
with ThreadPoolExecutor(max_workers=numInParallel) as ec:
return [ec.submit(submitNotebook, notebook) for notebook in notebooks]
notebooks = [
NotebookData("/Users/mynotebook",1200000, retry=0)
]
res = parallelNotebooks(notebooks, 2)
result = [f.result(timeout=1200000) for f in res] # This is a blocking call.
print(result)
Error:
Py4JJavaError Traceback (most recent call last)
<command-1143841910698378> in <module>
32 ]
33 res = parallelNotebooks(notebooks, 2)
---> 34 result = [f.result(timeout=1200000) for f in res] # This is a blocking call.
35 print(result)
<command-1143841910698378> in <listcomp>(.0)
32 ]
33 res = parallelNotebooks(notebooks, 2)
---> 34 result = [f.result(timeout=1200000) for f in res] # This is a blocking call.
35 print(result)
/usr/lib/python3.7/concurrent/futures/_base.py in result(self, timeout)
426 raise CancelledError()
427 elif self._state == FINISHED:
--> 428 return self.__get_result()
429
430 self._condition.wait(timeout)
/usr/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
382 def __get_result(self):
383 if self._exception:
--> 384 raise self._exception
385 else:
386 return self._result
/usr/lib/python3.7/concurrent/futures/thread.py in run(self)
55
56 try:
---> 57 result = self.fn(*self.args, **self.kwargs)
58 except BaseException as exc:
59 self.future.set_exception(exc)
<command-1143841910698378> in submitNotebook(notebook)
12 return dbutils.notebook.run(notebook.path, notebook.timeout, notebook.parameters)
13 else:
---> 14 return dbutils.notebook.run(notebook.path, notebook.timeout)
15 except Exception:
16 if notebook.retry < 1:
/local_disk0/tmp/1664351986642-0/dbutils.py in run(self, path, timeout_seconds, arguments, _NotebookHandler__databricks_internal_cluster_spec)
136 arguments,
137 __databricks_internal_cluster_spec,
--> 138 self.shell.currentJobGroup)
139
140 def __repr__(self):
/databricks/spark/python/lib/py4j-0.10.9-src.zip/py4j/java_gateway.py in __call__(self, *args)
1303 answer = self.gateway_client.send_command(command)
1304 return_value = get_return_value(
-> 1305 answer, self.gateway_client, self.target_id, self.name)
1306
1307 for temp_arg in temp_args:
/databricks/spark/python/pyspark/sql/utils.py in deco(*a, **kw)
125 def deco(*a, **kw):
126 try:
--> 127 return f(*a, **kw)
128 except py4j.protocol.Py4JJavaError as e:
129 converted = convert_exception(e.java_exception)
/databricks/spark/python/lib/py4j-0.10.9-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
326 raise Py4JJavaError(
327 "An error occurred while calling {0}{1}{2}.\n".
--> 328 format(target_id, ".", name), value)
329 else:
330 raise Py4JError(
Py4JJavaError: An error occurred while calling o1741._run.
: com.databricks.WorkflowException: com.databricks.NotebookExecutionException: FAILED
at com.databricks.workflow.WorkflowDriver.run(WorkflowDriver.scala:95)
at com.databricks.dbutils_v1.impl.NotebookUtilsImpl.run(NotebookUtilsImpl.scala:122)
at com.databricks.dbutils_v1.impl.NotebookUtilsImpl._run(NotebookUtilsImpl.scala:89)
at sun.reflect.GeneratedMethodAccessor820.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:380)
at py4j.Gateway.invoke(Gateway.java:295)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:251)
at java.lang.Thread.run(Thread.java:748)
Caused by: com.databricks.NotebookExecutionException: FAILED
at com.databricks.workflow.WorkflowDriver.run0(WorkflowDriver.scala:141)
at com.databricks.workflow.WorkflowDriver.run(WorkflowDriver.scala:90)
... 12 more

How to debug FactoInvestigate error: cannot open the connection

Anyone faced this error:
Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
I was trying to investigate the MCA results using:
Investigate(MCA_res, file = "MCA.Rmd", document = c("word_document", "pdf_document"))
> Investigate(MCA_res, file = "MCA.Rmd", document = c("word_document", "pdf_document"))
this hits an error after the following steps:
-- creation of the .Rmd file (time spent : 0s) --
-- detection of outliers (time spent : 0s) --
0 outlier(s) terminated
-- analysis of the inertia (time spent : 0.08s) --
12 component(s) carrying information : total inertia of 54.3%
-- components description (time spent : 6.25s) --
plane 1:2
plane 3:4
plane 5:6
plane 7:8
plane 9:10
plane 11:12
-- classification (time spent : 7.04s) --
3 clusters
-- annexes writing (time spent : 7.24s) --
-- saving data (time spent : 8.83s) --
-- outputs compilation (time spent : 8.83s) --
Quitting from lines 13-15 (MCA.Rmd)
**Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection**
In addition: Warning messages:
1: In if (document == "Word" | document == "word" | document == "doc" | :
the condition has length > 1 and only the first element will be used
2: In if (document == "html" | document == "HTML" | document == "HTML_document") { :
the condition has length > 1 and only the first element will be used
3: In if (document == "pdf" | document == "PDF") { :
the condition has length > 1 and only the first element will be used
4: In if (document == "word_document") { :
the condition has length > 1 and only the first element will be used
Any help understanding this will be highly appreciated.
Tx
Rj
The problem is with the adress of "Workspace.RData" who need to be loaded. I resolve by changing the source: "R/Investigate.R" line 74, writing:
writeRmd(paste0("library(FactoMineR)\nload('", getwd(),"/Workspace.RData')"), file = file, start = TRUE, stop = TRUE, options = "r, echo = FALSE")
on place of
writeRmd"library(FactoMineR)\nload('~/Workspace.RData')"), file = file, start = TRUE, stop = TRUE, options = "r, echo = FALSE")

How can i make a python file run another which is not in same directory?

This is my code...I have tried many solutions given on stackoverflow but i am not able to run another python file which is not in same directory
f.py
import os
print "Start..."
file='"C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical
Session on R\Session II - Regression\run.py"'
os.system('python file ')
print "Done"
Output:
Fatal error: cannot open file 'file': No such file or directory
run.py
import os
print "Start..."
files=r'"C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical
Session on R\Session II - Regression\decisionTree.R"'
os.system('Rscript '+files)
print "Done"
I get the desired result when i run run.py.
Output:
C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical Session
on R\
Session II - Regression>python r.py
Start...
START
elapsed
0.17
Step 1: Library Inclusion
Step 2: Variable Declaration[1]
[1] "regressionDataSet.csv"
Step 3: Data Loading RMSD
irNumber
14395 1.167 5364.27 4616.64
15435 2.500 25468.10 475274.00 -
8739 4.039 5921.03 7071.89
11586 0.000 14192.70 75413.00
13765 0.000 17432.40 245147.00 -
10087 3.814 7333.51 26580.70
[1] 16382
[1] "RMSD" "Area"
[5] "SS" "ResidueLeng
Step 4: Counting dataset[1] 1638
Step 5: Choose Target Variable[1
Step 6: Choose Inputs Variable[1
"SS"
[5] "ResidueLength" "PairNumber"
[1] 6
Step 7: Select training dataset
th PairNumber RMSD
14395 5364.27 4616.64 -696.
15435 25468.10 475274.00 -10600.
8739 5921.03 7071.89 -1658.
11586 14192.70 75413.00 -7939.
13765 17432.40 245147.00 -10885.
10087 7333.51 26580.70 -2746.
[1] 8191
Step 8: Select testing dataset
PairNumber RMSD
10216 20510.40 254178.0 44500.0
2385 9981.42 28499.0 -4789.0
1886 21107.10 192443.0 -4860.0
13684 17765.00 76543.0 -8164.0
10319 6308.91 10287.3 -3370.0
13088 5844.34 11139.7 -1879.7
[1] 8192
Step 9: Model Building -> decis
ength + PairNumber
n= 8191
node), split, n, deviance, yval
* denotes terminal node
1) root 8191 23819.88000 2.364
2) Energy< -6161.885 1592 4
4) ResidueLength< 387.5 74
8) Energy< -7785.3 262
9) Energy>=-7785.3 481
5) ResidueLength>=387.5 84
10) Energy< -12910.5 173
11) Energy>=-12910.5 676
22) ResidueLength< 467.
44) ResidueLength>=39
45) ResidueLength< 39
23) ResidueLength>=467.
3) Energy>=-6161.885 6599 17
6) SS< 21.5 1584 3795.813
7) SS>=21.5 5015 13126.850
14) Energy< -3971.125 163
28) ResidueLength< 192.
29) ResidueLength>=192.
58) ResidueLength< 26
116) Energy< -4680.5
117) Energy>=-4680.5
59) ResidueLength>=26
15) Energy>=-3971.125 337
30) Area< 8601.98 1655
60) Energy< -2933.36
61) Energy>=-2933.36
31) Area>=8601.98 1721
Step 10: Prediction using -> de
13684 10319 13088
3.24618361 0.51722167 3.10727318
Step 11: Extracting Actual[1] 3.
Step 12: Model Evaluation[1] 0.5
[1] 0.25
[1] 1.19
[1] 48.19
elapsed
0.53
null device
1
modelName r R rm
elapsed decisionTree 0.5 0.25 1.
Step 13: Writing to file
Step 14: Saving the Model -> dec
Done
Total Time Taken: 0.53 secDone
But i get the following error when i run it through f.py
Error:
Start...
Start...
START
elapsed
0.18
Step 1: Library Inclusion
Step 2: Variable Declaration[1] "decisionTree"
[1] "regressionDataSet.csv"
Step 3: Data LoadingError in file(file, "rt") : cannot open the connec
Calls: read.csv -> read.table -> file
In addition: Warning message:
In file(file, "rt") :
cannot open file 'regressionDataSet.csv': No such file or directory
Put an r in front of your file path, so that the backslashes \ don't escape strings where you don't want them to be escaped (see also this question).
Secondly os.system('python file') will literally execute python file, your variable isn't being used.
Also make sure there's no linebreak your file path (just one long line).
import os
print "Start..."
folder = r'C:\Users\Mohit\Desktop\ML PROJECT\Practical Session on R\Practical Session on R\Session II - Regression'
file= r'"{}\run.py"'.format(folder)
os.chdir(folder)
os.system('python '+file)
print "Done"

r system doesn't work when trying 7zip

Hi I'm trying to use R to control unzipping a file.
I've added 7z into PATH, and did
7z e hat.2015-09-26T01-10-02.gz
and it worked.
Now in R, i'm in the same directory, and i tried
> command1 = paste0('7z e ', drop.file)
> command1
[1] "7z e hat.2015-09-26T01-10-02.gz"
> system(command1, intern=T)
Error in system(command1, intern = T) : '7z' not found
> system2(command1)
Warning message:
running command '"7z e hat.2015-09-26T01-10-02.gz"' had status 127
> shell(command1)
'7z' is not recognized as an internal or external command,
operable program or batch file.
Warning messages:
1: running command 'C:\Windows\system32\cmd.exe /c 7z e hat.2015-09-26T01-10-02.gz' had status 1
2: In shell(command1) :
'7z e hat.2015-09-26T01-10-02.gz' execution failed with error code 1
It's little bit raw, but try this out (:
Only Windows. It's uses CMD
ZiparEm7zip = function(sQualPasta)
{
sWDTava = getwd()
setwd(dirname(sQualPasta))
sQuem = gsub("[/]", "\\\\", sQualPasta)
dirname(sQuem)
NomeArquivo = paste0("eufaco7zip",".bat")
sNomePasta7zip = basename(sQuem)
sArquivoSaida = basename(sQuem)
sQualPasta7zip = sQuem
if(dir.exists("C:/Program Files/7-Zip/"))
{
sTexto = "set PATH=%PATH%;C:\\Program Files\\7-Zip\\"
}else if(dir.exists("C:/Program Files (x86)/7-Zip/"))
{
sTexto = "set PATH=%PATH%;C:\\Program Files (x86)\\7-Zip\\"
}else
{
stop("Error, o 7zip not installed?")
}
sTexto2 = paste0("\npushd ",sQualPasta7zip)
sTexto3 = paste0("\n7z a -r ../",sArquivoSaida," *")
sTexto4 = '\n( del /q /f "%~f0" >nul 2>&1 & exit /b 0 )'
cat(sTexto,file=NomeArquivo,append = TRUE)
cat(sTexto2,file=NomeArquivo,append = TRUE)
cat(sTexto3,file=NomeArquivo,append = TRUE)
cat(sTexto4,file=NomeArquivo,append = TRUE)
shell.exec(NomeArquivo)
while(file.exists(NomeArquivo))
{
Sys.sleep(10)
}
setwd(sWDTava)
return(TRUE)
}
Try like:
ZiparEm7zip("F:/MYFOLDER")

Resources