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

Use Artifacts.toml to access VARNA jar file #12

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[VARNAv3-93_jar]
git-tree-sha1 = "7141dcd09e8fced75b19ca928bd4a790af61ffc2"
lazy = true

[[VARNAv3-93_jar.download]]
sha256 = "58e19c60214ca15f8aefe91ba0feafde3c21b2f30700d8b5b718a3c5bf7aaa5d"
url = "https://gist.github.com/marcom/e9f305a65fc6fbd0fef6df2d66d92f88/raw/7141dcd09e8fced75b19ca928bd4a790af61ffc2.tar.gz"
3 changes: 1 addition & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ version = "0.3.0"
[deps]
BioStockholm = "eeb925a3-6f9d-43e6-829e-e0ea03b76ecf"
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
R2R_jll = "1e27f72a-4876-5c10-8678-3341fdb8ba55"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
ViennaRNA = "05a721ad-238d-4945-8c85-8b5c1fff3465"

Expand All @@ -31,7 +31,6 @@ Luxor = "3.3"
PrecompileTools = "1"
R2R_jll = "=1.0.6"
Requires = "1.3"
Scratch = "1.1"
UnicodePlots = "3"
ViennaRNA = "0.11"
julia = "1.6"
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ VARNA.plot_compare(dbn1="(((.....)))", seq1="GCGAAAAACGC",
You will need a working Java installation (can be headless i think).
You can test this by running:
```julia
run(`java -version`)
Sys.which("java")
```
If you don't get an error, plotting with VARNA should work.
If you get a file path (e.g. `"/usr/bin/java"`) and not `nothing`,
plotting with VARNA should work.

The VARNA jar file will get downloaded automatically the first time
you plot something with VARNA. It gets stored in a scratch space that
gets cleaned up by the Julia package manager when you uninstall
PlotRNA.
you plot something with one of the VARNA functions. It gets stored in
the Julia artifacts directory.


#### VARNA plot options
Expand Down
26 changes: 5 additions & 21 deletions src/varna.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,9 @@ module VARNA
# `-foo` : error, no argument for option foo
# `-foo bar` : no error or warning

using Scratch: @get_scratch!

const _download_url = "https://varna.lri.fr/bin/VARNAv3-93.jar"

# this will be filled in by `__init__()`
_download_cache = ""

function __init__()
global _download_cache = @get_scratch!("jar")
end

function _download_varna_jar(url=_download_url)
fname = joinpath(_download_cache, basename(url))
if !isfile(fname)
@info "downloading VARNA jar file from $url"
download(url, fname)
end
return fname
end
# TODO, this doesn't work: using LazyArtifacts: @artifact_str
using LazyArtifacts
_get_varna_jar() = artifact"VARNAv3-93_jar/VARNAv3-93.jar"

# VARNA-3.93 supported formats: JPEG,PNG,EPS,XFIG,SVG
const _map_fileendings_to_mime = Dict(
Expand Down Expand Up @@ -187,7 +171,7 @@ function plot(dbn::AbstractString;
fileformat::AbstractString="svg",
verbose::Bool=false,
plot_opts...)
varna_jarpath = _download_varna_jar()
varna_jarpath = _get_varna_jar()
if length(dbn) != length(seq)
throw(ArgumentError("structure and sequence must have same length: $(length(dbn)) != $(length(seq))"))
end
Expand Down Expand Up @@ -226,7 +210,7 @@ function plot_compare(; dbn1::AbstractString,
fileformat::AbstractString="svg",
verbose::Bool=false,
plot_opts...)
varna_jarpath = _download_varna_jar()
varna_jarpath = _get_varna_jar()
if length(dbn1) != length(dbn2) || length(dbn1) != length(seq1) || length(dbn1) != length(seq2)
throw(ArgumentError("all structures and sequences must have same length, here they are: " *
"dbn1=$(length(dbn1)), seq1=$(length(seq1)), dbn2=$(length(dbn2)), seq2=$(length(seq2)))"))
Expand Down