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

Arguments with spaces cause errors #26

Closed
arisp99 opened this issue Mar 8, 2022 · 1 comment
Closed

Arguments with spaces cause errors #26

arisp99 opened this issue Mar 8, 2022 · 1 comment
Labels
bug unexpected problem or unintended behavior
Milestone

Comments

@arisp99
Copy link
Member

arisp99 commented Mar 8, 2022

Bug Description

When arguments contain spaces, argparse is unable to parse the spaces and causes our code to crash. I encountered this error when attempting to run through the analysis test run. When running through the first section of the tutorial, the user is asked to specify the probe sets used before running the wrangler app. In the example, we write

probe_sets_used="DR1,VAR4"

However, if the user adds a space in between these two probe sets:

probe_sets_used="DR1, VAR4"

and tries to run the wrangler app using the following:

singularity run --app wrangler \
    -B $project_resources:/opt/project_resources \
    -B $fastq_dir:/opt/data \
    -B $wrangler_dir:/opt/analysis \
    $miptools -p $probe_sets_used -s $sample_sets_used -e $experiment_id \
    -l  $sample_list -c $cpu_number -m $min_capture_length

the app will fail with the following error: generate_wrangler_scripts.py: error: unrecognized arguments: VAR4.

Our code does aim to deal with these cases by cleaning up spaces in the following lines:

# get sample sets and probe sets to be processed.
# sample sets should be provided as a comma separated text
# sometimes semicolon is used and spaces may be included by mistake
# we'll check for these potential mistakes and create a list of sample sets
# to process.
sam_set = args["sample_sets"]
sam_set = sam_set.split(",")
sample_sets = []
for s in sam_set:
sample_sets.extend(s.strip().split(";"))
sample_sets = set([s.strip() for s in sample_sets])
# probe sets are provided and will be processed similarly to sample sets
pr_set = args["probe_sets"]
pr_set = pr_set.split(",")
probe_sets = []
for p in pr_set:
probe_sets.extend(p.strip().split(";"))
probe_sets = set([p.strip() for p in probe_sets])

However, the code fails before we are able to reach this stage. It seems that the error is triggered by argparse here:

args = vars(parser.parse_args())

Suggested Implementation

Seeing as we are unable to deal with spaces within the python file, I suggest we deal with any spaces and misformatted arguments within the wrangler app before feeding in our arguments to the python script. We can do simple string manipulation in bash as outlined here. For instance, to remove whitespace:

probe_sets_used="DR1, VAR4"
echo bash ${probe_sets_used// /}
#> DR1,VAR4
@arisp99 arisp99 added the bug unexpected problem or unintended behavior label Mar 8, 2022
@aydemiro
Copy link
Contributor

aydemiro commented Mar 8, 2022

yes we can change the app code to:

    # remove accidental spaces
    probe_sets=${probe_sets// /}
    sample_sets=${sample_sets// /}

    # Create wrangler bash scripts using python
    python /opt/src/generate_wrangler_scripts.py \
    -c ${cpu_count} -e ${experiment_id} ${keep_files} \
    -l /opt/analysis/${sample_list} -m ${min_capture_length} \
    -n ${server_number} -p ${probe_sets} -s ${sample_sets} \
    -w ${cluster_script} -x ${stitch_options}

Edit: probe_sets and sample_sets parameters are used in the app code instead of probe_sets_used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants