Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the sed command in Singularity Exec does not work. Similar with Redirect ">" symbol. #101

Open
jjacobson95 opened this issue Apr 12, 2023 · 6 comments

Comments

@jjacobson95
Copy link

jjacobson95 commented Apr 12, 2023

Command line works as expected:
singularity exec --writable-tmpfs instance://reclusive_cat_2780 sed -i 's/REPLACE_THIS_LINE/ <parameter name="Raw data file names"><file>\/Work\/III_mzML\/Dorrestein_GnPS_P14_G10_7V_Rep01_Neg_29Dec20_Fiji_Infusion_Min50_MA-csum-Min20_3.mzML<\/file><\/parameter>/' /Work/MZmine_FeatureFinder-batch.xml

Python Command doesn't work:

file_name = "test_file"
command_list_1 = """sed -i \'s/REPLACE_THIS_LINE/        <parameter name="Raw data file names"><file>\/Work\/III_mzML\/""" +file_name + """<\/file><\/parameter>/\' /Work/MZmine_FeatureFinder-batch.xml"""`

Client.execute(myinstance,command_list_1, options=['--writable-tmpfs'],quiet=False)`

Error message:
/bin/sed: -e expression #1, char 1: unknown command: `''

@vsoch
Copy link
Member

vsoch commented Apr 12, 2023

Try putting the sed command in a bash script and running that. We split the woman’s with shlex and your sed FU probably doesn’t work well with that approach.

@jjacobson95
Copy link
Author

Just wrote a quick python script to do it instead. Still would be a great thing to fix for users. I’m converting a docker pipeline to singularity for HPC and took quite a while to track down exactly where it was failing.

@vsoch
Copy link
Member

vsoch commented Apr 12, 2023

Try running the command with subprocess as spython does and you will likely run into the same issue.

@vsoch
Copy link
Member

vsoch commented Apr 12, 2023

spython isn’t a workflow tool - it’s a thin wrapper to running singularity. Likely a workflow tool would take a command and instead write to a temporary file first, but I consider that out of scope here because it’s not up to spython to make that decision for the user.

@jjacobson95
Copy link
Author

Okay, your call of course! Just was surprised that the wrapper has a bit less functionality than the command line interface because it seems pretty well supported. Could be helpful to note in documentation for future users.

@vsoch
Copy link
Member

vsoch commented Apr 12, 2023

The wrapper uses subprocess, and any tool that does similar will have similar issue with things like pipe or sed. If you’d like to do a PR to update docs with a suggestion I’d be happy to review that. I do not see singularity Python as being responsible for managing a workflow for which it’s really better practice to write complex commands to a bash script so they are properly run with a shell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants