From 23c50cc557140d8f1c600493901209c2ae3552cb Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 24 Oct 2023 14:46:07 -0500 Subject: [PATCH] Update to newer packages (#5) --- .github/workflows/CI.yml | 69 +++++++++++++++++++++++++++++++++++++++ .gitignore | 9 +++-- .travis.yml | 33 ------------------- Project.toml | 41 +++++++++++------------ appveyor.yml | 47 -------------------------- deps/build.jl | 6 ++-- ext/AllenBrainMakieExt.jl | 14 ++++++++ src/AllenBrain.jl | 19 ++--------- src/genes.jl | 19 +---------- src/images.jl | 10 ++---- src/ontology.jl | 6 ++-- src/projections.jl | 2 +- src/visualize.jl | 2 ++ test/runtests.jl | 13 ++++++-- 14 files changed, 135 insertions(+), 155 deletions(-) create mode 100644 .github/workflows/CI.yml delete mode 100644 .travis.yml delete mode 100644 appveyor.yml create mode 100644 ext/AllenBrainMakieExt.jl diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..c90f8e9 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,69 @@ +name: CI +on: + push: + branches: + - main + tags: ['*'] + pull_request: +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - '1.9' + - '1' + os: + - ubuntu-latest + arch: + - x64 + steps: + - uses: actions/checkout@v3 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/cache@v1 + - uses: julia-actions/julia-buildpkg@v1 + env: + SSH_AUTH_SOCK: /tmp/ssh_agent.sock + HOME: /home/runner + - uses: julia-actions/julia-runtest@v1 + - uses: julia-actions/julia-processcoverage@v1 + - uses: codecov/codecov-action@v3 + with: + files: lcov.info + # docs: + # name: Documentation + # runs-on: ubuntu-latest + # permissions: + # contents: write + # statuses: write + # steps: + # - uses: actions/checkout@v3 + # - uses: julia-actions/setup-julia@v1 + # with: + # version: '1' + # - name: Configure doc environment + # run: | + # julia --project=docs/ -e ' + # using Pkg + # Pkg.develop(PackageSpec(path=pwd())) + # Pkg.instantiate()' + # - uses: julia-actions/julia-buildpkg@v1 + # - uses: julia-actions/julia-docdeploy@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # - run: | + # julia --project=docs -e ' + # using Documenter: DocMeta, doctest + # using TaylorRemainders + # DocMeta.setdocmeta!(TaylorRemainders, :DocTestSetup, :(using TaylorRemainders); recursive=true) + # doctest(TaylorRemainders)' diff --git a/.gitignore b/.gitignore index 2afde0e..815cf93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ -*.jl.cov *.jl.*.cov +*.jl.cov *.jl.mem -data -Manifest.toml +/Manifest.toml +/docs/Manifest.toml +/docs/build/ +/deps/build.log +/data diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 023bb78..0000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -## Documentation: http://docs.travis-ci.com/user/languages/julia/ -language: julia -os: - - linux - - osx -julia: - - 1 - - nightly -notifications: - email: false -git: - depth: 99999999 - -## uncomment the following lines to allow failures on nightly julia -## (tests will run but not make your overall status red) -#matrix: -# allow_failures: -# - julia: nightly - -## uncomment and modify the following lines to manually install system packages -#addons: -# apt: # apt-get for linux -# packages: -# - gfortran -#before_script: # homebrew for mac -# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi - -## uncomment the following lines to override the default test script -#script: -# - julia -e 'Pkg.clone(pwd()); Pkg.build("AllenBrain"); Pkg.test("AllenBrain"; coverage=true)' - -after_success: - - julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' diff --git a/Project.toml b/Project.toml index 79aecd3..018dfa1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,16 +1,15 @@ name = "AllenBrain" uuid = "0a79a13e-b89b-5a1e-b6bf-ef7ebeca6040" authors = ["Tim Holy "] -version = "0.1.0" +version = "0.2.0" [deps] AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9" -ColorVectorSpace = "c3611d14-8923-5661-9e6a-0046d554d3a4" CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298" FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" -ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795" IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959" Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" @@ -20,31 +19,33 @@ LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" NRRD = "9bb6cfbd-7763-5393-b1b5-1c8e09872146" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca" -Requires = "ae029012-a4dd-5104-9daa-d747884805df" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" +[weakdeps] +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" + +[extensions] +AllenBrainMakieExt = "Makie" + [compat] -AxisArrays = "0.3, 0.4" -ColorVectorSpace = "0.6, 0.8" -CoordinateTransformations = "0.5" +AxisArrays = "0.4" +CoordinateTransformations = "0.6" FileIO = "1" -HTTP = "0.8" -ImageCore = "0.8.1" -ImageMagick = "0.7, 1" -ImageTransformations = "0.7, 0.8" -IndirectArrays = "0.5" -Interpolations = "0.11, 0.12" -IntervalSets = "0.3, 0.4" +HTTP = "1" +ImageCore = "0.9, 0.10" +ImageTransformations = "0.10" +IndirectArrays = "1" +Interpolations = "0.14" +IntervalSets = "0.7" JSON = "0.21" -LightGraphs = "1" -NRRD = "0.5, 0.6" -OffsetArrays = "0.11, 1" +NRRD = "0.6" +OffsetArrays = "1" ProgressMeter = "1" -Requires = "1" -StaticArrays = "0.10, 0.11, 0.12" -Unitful = "0.17, 0.18, 1" +StaticArrays = "1" +Unitful = "1" +julia = "1.9" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index f989645..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,47 +0,0 @@ -environment: - matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - -## uncomment the following lines to allow failures on nightly julia -## (tests will run but not make your overall status red) -#matrix: -# allow_failures: -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - -branches: - only: - - master - - /release-.*/ - -notifications: - - provider: Email - on_build_success: false - on_build_failure: false - on_build_status_changed: false - -install: - - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" -# If there's a newer build queued for the same PR, cancel this one - - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` - https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` - Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` - throw "There are newer queued builds for this pull request, failing early." } -# Download most recent Julia Windows binary - - ps: (new-object net.webclient).DownloadFile( - $env:JULIA_URL, - "C:\projects\julia-binary.exe") -# Run installer silently, output to C:\projects\julia - - C:\projects\julia-binary.exe /S /D=C:\projects\julia - -build_script: -# Need to convert from shallow to complete for Pkg.clone to work - - IF EXIST .git\shallow (git fetch --unshallow) - - C:\projects\julia\bin\julia -e "versioninfo(); - Pkg.clone(pwd(), \"AllenBrain\"); Pkg.build(\"AllenBrain\")" - -test_script: - - C:\projects\julia\bin\julia -e "Pkg.test(\"AllenBrain\")" diff --git a/deps/build.jl b/deps/build.jl index c07d935..ba0313f 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -10,7 +10,7 @@ genes = joinpath(mousedir, "genes.json") if !isfile(sg) rq = HTTP.request("GET", "http://api.brain-map.org/api/v2/structure_graph_download/1.json") - data = JSON.parse(String(rq.data)) + data = JSON.parse(String(rq.body)) hierarchy = data["msg"][1] open(sg, "w") do io @@ -19,9 +19,9 @@ if !isfile(sg) end if !isfile(genes) - info("Downloading genes database. This will take a while, but only needs to be done once.") + @info "Downloading genes database. This will take a while, but only needs to be done once." rq = HTTP.request("GET", "http://api.brain-map.org/api/v2/data/Gene/query.json?criteria=products[id\$eq1]"; query=Dict("num_rows"=>19991)) - data = JSON.parse(String(rq.data)) + data = JSON.parse(String(rq.body)) g = data["msg"] open(genes, "w") do io write(io, JSON.json(g)) diff --git a/ext/AllenBrainMakieExt.jl b/ext/AllenBrainMakieExt.jl new file mode 100644 index 0000000..87b275f --- /dev/null +++ b/ext/AllenBrainMakieExt.jl @@ -0,0 +1,14 @@ +module AllenBrainMakieExt + +using AllenBrain, Makie + +# NOTE: this was written against GLVisualize which is deprecated for +# Makie. The code below likely needs updating. +function AllenBrain.visualize_volume(volumedata) + window = Makie.glscreen() + volume = Makie.visualize(volumedata, :absorption) + Makie._view(volume, window) + @schedule Makie.renderloop(window) +end + +end diff --git a/src/AllenBrain.jl b/src/AllenBrain.jl index 2a5f0ce..38b79dd 100644 --- a/src/AllenBrain.jl +++ b/src/AllenBrain.jl @@ -3,11 +3,9 @@ module AllenBrain using Statistics using JSON, LightGraphs, IndirectArrays, AxisArrays, OffsetArrays using StaticArrays, CoordinateTransformations -using ImageMagick, ImageTransformations, ImageCore, Interpolations -using ColorVectorSpace +using ImageTransformations, ImageCore, Interpolations using IntervalSets, ProgressMeter, FileIO using Unitful: μm -using Requires import HTTP export # @@ -42,7 +40,7 @@ function dataset(species, category) species == "mouse" && return joinpath(mousedir, "structure_graph.json") elseif startswith(category, "annotation") && species == "mouse" if !endswith(category, ".nrrd") - if !ismatch(r"[0-9]$", category) + if match(r"[0-9]$", category) === nothing category = category*"_25" end category = category*".nrrd" @@ -70,17 +68,4 @@ include("projections.jl") include("genes.jl") include("visualize.jl") -function __init__() - # NOTE: this was written against GLVisualize which is deprecated for - # Makie. The code below likely needs updating. - @require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" begin - function visualize_volume(volumedata) - window = Makie.glscreen() - volume = Makie.visualize(volumedata, :absorption) - Makie._view(volume, window) - @schedule Makie.renderloop(window) - end - end -end - end # module diff --git a/src/genes.jl b/src/genes.jl index 5eb7b98..c33ab2d 100644 --- a/src/genes.jl +++ b/src/genes.jl @@ -6,7 +6,7 @@ const planedict = Dict("coronal"=>1, "sagittal"=>2) function query_insitu(key::AbstractString; plane="coronal", fieldname="acronym") rq = HTTP.request("GET", "http://api.brain-map.org/api/v2/data/SectionDataSet/query.json?criteria=products[id\$eq1],genes[$fieldname\$eq'$key']&include=section_images,alignment3d,section_images(alignment2d)") - data = JSON.parse(String(rq.data)) + data = JSON.parse(String(rq.body)) planeid = planedict[plane] for sectiondataset in data["msg"] if sectiondataset["plane_of_section_id"] == planeid @@ -66,23 +66,6 @@ function download_insitu_images(sectiondataset::Dict, bb::BoundingBox, dirname; "boundingbox"=>bb)) end - # showall(filenames) - # showall(slicepos) - # sz = imagesize(joinpath(dirname, filenames[1])) - # for i = 2:length(filenames) - # sz = map(max, sz, imagesize(joinpath(dirname, filenames[i]))) - # end - # img2d = load(joinpath(dirname, first(filenames))) - # img = similar(img2d, sz[2], sz[1], length(filenames)) - # fill!(img, zero(eltype(img))) - # for i = 1:length(filenames) - # fn = joinpath(dirname, filenames[i]) - # if imagesize(fn) == sz - # img[:,:,i] = load(fn) - # end - # end - # resp = median(diff(slicepos)) - # FileIO.save(joinpath(dirname, "merged.nrrd"), AxisArray(img, (:P, :I, :R), (resp, res, res))) # function download_insitu_images(genekey::AbstractString, x, y, dirname=genekey; plane="coronal", fieldname="acronym", downsample=0) # if !isdir(dirname) diff --git a/src/images.jl b/src/images.jl index 3212d09..c7b2bb3 100644 --- a/src/images.jl +++ b/src/images.jl @@ -11,7 +11,7 @@ function query_reference2image(sectiondataset::Dict, x, y, z) xr, yr, zr = inmicrons(x), inmicrons(y), inmicrons(z) str = "http://api.brain-map.org/api/v2/reference_to_image/$refspace.json?x=$xr&y=$yr&z=$zr§ion_data_set_ids=$id" rq = HTTP.request("GET", str) - data = JSON.parse(String(rq.data)) + data = JSON.parse(String(rq.body)) data["msg"][1]["image_sync"] end @@ -24,7 +24,7 @@ return the posterior, inferior, right coordinates `p`, `i`, `r` in microns. function query_image2reference(sectionimageid::Integer, x, y) str = "http://api.brain-map.org/api/v2/image_to_reference/$sectionimageid.json?x=$x&y=$y" rq = HTTP.request("GET", str) - data = JSON.parse(String(rq.data)) + data = JSON.parse(String(rq.body)) ret = data["msg"]["image_to_reference"] ret["x"], ret["y"], ret["z"] end @@ -159,9 +159,3 @@ function isinrange(idx, pos, x, Δx) 1 <= idx <= length(pos) || return false abs(pos[idx] - x) <= Δx end - -function imagesize(filename) - wand = ImageMagick.MagickWand() - ImageMagick.readimage(wand, filename) - size(wand) -end diff --git a/src/ontology.jl b/src/ontology.jl index 474010d..28837c8 100644 --- a/src/ontology.jl +++ b/src/ontology.jl @@ -16,7 +16,7 @@ end Return the structure graph `g` and list `vertexlist` of metadata for nodes. """ function ontology(filename) - str = readstring(dataset(filename, "ontology")) + str = read(dataset(filename, "ontology"), String) hierarchy = JSON.parse(str) g = DiGraph() add_vertex!(g) # for the root node @@ -49,9 +49,9 @@ function annotation(resolution=50; species="mouse") return AxisArray(anno.data, (:P, :I, :R), (r, r, r)) end -function download_annotation(resolution=50) +function download_annotation(resolution=50; species="mouse", year=2016) dest = joinpath(mousedir, "annotation_$resolution.nrrd") - download("http://download.alleninstitute.org/informatics-archive/current-release/mouse_ccf/annotation/ccf_2016/annotation_$resolution.nrrd", dest) + download("http://download.alleninstitute.org/informatics-archive/current-release/$(species)_ccf/annotation/ccf_$year/annotation_$resolution.nrrd", dest) end """ diff --git a/src/projections.jl b/src/projections.jl index 7288487..a52cb0b 100644 --- a/src/projections.jl +++ b/src/projections.jl @@ -1,6 +1,6 @@ function query_projection(id) rq = HTTP.request("GET", "http://api.brain-map.org/api/v2/data/WellKnownFile/query.json?criteria=well_known_file_type[name\$eq'ImagesResampledTo25MicronARA'][attachable_id\$eq$id]") - data = JSON.parse(String(rq.data)) + data = JSON.parse(String(rq.body)) data["msg"][1] end diff --git a/src/visualize.jl b/src/visualize.jl index 8284fc7..bad47d7 100644 --- a/src/visualize.jl +++ b/src/visualize.jl @@ -40,3 +40,5 @@ function colorize!(dest::AbstractArray{To}, ano::AbstractArray{Ti}, end IndirectArray(dest, colorlist) end + +function visualize_volume end diff --git a/test/runtests.jl b/test/runtests.jl index 6c24081..a94434b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,14 @@ using AllenBrain using Test -# write your own tests here -@test 1 == 2 +@testset "AllenBrain" begin + # These are only "does it run" tests? + species = "mouse" + resolution = 50 + g, vertexlist = ontology(species) + if !isfile(AllenBrain.dataset(species, "annotation_"*string(resolution))) + download_annotation(resolution; species) + end + a = annotation(resolution; species) + download_projection(293546902, tempname()) +end