I have a python script that I use with rpy2, however in my code I need to repeatedly use R code, I do so by using the rpy2.robjects() function.
I have noticed that the first run of the R code works perfectly, no errors and no crushes. However while going into the second loop, I get the following error:
Unable top open index 'my_index'. Please make sure that the correct prefix is specified and you have the permission to read these files. For example, if there are files '/opt/my_index.reads', '/opt/my_index.files' and etc, the index prefix should be specified as '/opt/my_index' without any suffix.
File "/home/lishana/miniconda3/envs/qiime2-new/bin/yamas", line 8, in <module>
sys.exit(main())
File "/home/lishana/miniconda3/envs/qiime2-new/lib/python3.8/site-packages/yamas/__init__.py", line 123, in main
continue_from(dataset_id,continue_path,data_type, args.verbose, specific_location)
File "/home/lishana/miniconda3/envs/qiime2-new/lib/python3.8/site-packages/yamas/dataset_downloading.py", line 60, in continue_from
visualization_continue(dataset_id,continue_path, data_type, verbose_print, specific_location)
File "/home/lishana/miniconda3/envs/qiime2-new/lib/python3.8/site-packages/yamas/create_visualization.py", line 465, in visualization_continue
metaphlan_extraction(reads_data, dataset_id)
File "/home/lishana/miniconda3/envs/qiime2-new/lib/python3.8/site-packages/yamas/create_visualization.py", line 181, in metaphlan_extraction
pathways(pathways_metaphlan_output, fastq_name, reads_data, "/home/lishana/pathways")
File "/home/lishana/miniconda3/envs/qiime2-new/lib/python3.8/site-packages/yamas/pathways.py", line 250, in pathways
robjects.r(r_code)
File "/home/lishana/miniconda3/envs/qiime2-new/lib/python3.8/site-packages/rpy2/robjects/__init__.py", line 509, in __call__
res, visible = rinterface.evalr_expr_with_visible( # type: ignore
File "/home/lishana/miniconda3/envs/qiime2-new/lib/python3.8/site-packages/rpy2/rinterface.py", line 192, in evalr_expr_with_visible
raise embedded.RRuntimeError(_rinterface._geterrmessage())
rpy2.rinterface_lib.embedded.RRuntimeError: Error in .stop_quietly() :
Now I know the problem that crushed the R code is presented in the beginning of the error message, however after rerunning the script it works, and crushes on the next loop (I have an if statement to not run the R code on something I run it on)
The line that the code is crushing on is the following:
if (readfile2 != "") {{
align(index = "my_index", readfile1 = readfile1, readfile2 = readfile2, type = "rna", output_file = file.path(folder_path, "aligned_reads.bam"))
}} else {{
align(index = "my_index", readfile1 = readfile1, type = "rna", output_file = file.path(folder_path, "aligned_reads.bam"))
}}
Couple extra notes:
- In the code I have an option to check if a library has already been called for, and if it has been it will not call it again to save time – the error happened before I implemented that.
- I delete the aligned_reads.bam after each iteration of the loop, and I save it each time in a different location.
anyone knows how to resolve this?
thanks!!