Skip to content

Commit

Permalink
Cli fix (#90)
Browse files Browse the repository at this point in the history
* flip add_cli_args! optunderscores

* actually assign results

* update other humann function calls

* add tests

* add tests
  • Loading branch information
kescobo authored Oct 21, 2021
1 parent e247dc3 commit fcf7a80
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion docs/src/humann.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ See [Using Conda.jl](@ref using-conda)

You can attach names to features using [`humann_rename`](@ref).


## HUMAnN for multiple samples

[Official tutorial link](https://github.com/biobakery/biobakery/wiki/humann3#42-humann-for-multiple-samples)
Expand Down
4 changes: 2 additions & 2 deletions src/humann.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function humann(inputfile, output; kwargs...)
append!(c, ["--metaphlan-options", "'--bowtie2db $(ENV["METAPHLAN_BOWTIE2_DB"])'"])
end

add_cli_kwargs!(c, kwargs)
add_cli_kwargs!(c, kwargs; optunderscores=false)

@info "Running command: $(Cmd(c))"
return run(Cmd(c))
Expand Down Expand Up @@ -271,6 +271,6 @@ function humann_barplot(comm::CommunityProfile, outpath; kwargs...)
cmd = ["humann_barplot", "--i", tmp, "-o", outpath,
"--last-metadata", string(last(keys(first(metadata(comm)))))]

add_cli_kwargs!(cmd, kwargs)
add_cli_kwargs!(cmd, kwargs; optunderscores=false)
run(Cmd(cmd))
end
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function install_deps(env=:BiobakeryUtils; force=false)
return nothing
end

function add_cli_kwargs!(cmd, kwargs; optunderscores=false)
function add_cli_kwargs!(cmd, kwargs; optunderscores=true)
for (key,val) in pairs(kwargs)
if val isa Bool
val && push!(cmd, string("--", key))
Expand All @@ -44,7 +44,7 @@ function add_cli_kwargs!(cmd, kwargs; optunderscores=false)
append!(cmd, [string("--", key), string(val)])
end
end
!optunderscores && map(c-> startswith(c, "--") ? replace(c, "_"=>"-") : c, cmd)
!optunderscores && map!(c-> startswith(c, "--") ? replace(c, "_"=>"-") : c, cmd, cmd)
return cmd
end

Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ isdir(Conda.bin_dir(:BiobakeryUtils)) || BiobakeryUtils.install_deps()
ENV["PATH"] = ENV["PATH"] * ":" * Conda.bin_dir(:BiobakeryUtils)

@testset "CLI" begin
@testset "Utilities" begin
cmd = ["thing", "foo_bar"]
cmd2 = copy(cmd)

BiobakeryUtils.add_cli_kwargs!(cmd, Dict(:some_thing=> "foo", :bool=> true))
@test all(cmd .== ["thing", "foo_bar", "--some_thing", "foo", "--bool"])
BiobakeryUtils.add_cli_kwargs!(cmd2, Dict(:some_thing=> "foo", :bool=> true); optunderscores=false)
@test all(cmd2 .== ["thing", "foo_bar", "--some-thing", "foo", "--bool"])
end

@testset "Metaphlan" begin
@test BiobakeryUtils.check_for_install("metaphlan") |> isnothing
@test BiobakeryUtils.check_for_install("merge_metaphlan_tables.py") |> isnothing
Expand Down

2 comments on commit fcf7a80

@kescobo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/47131

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" fcf7a8012a8140f41145c487943a74be04953ef8
git push origin v0.5.0

Please sign in to comment.