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

Prepare for integration with SpeciesInteractionNetworks #33

Merged
merged 6 commits into from
Jun 25, 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
3 changes: 3 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
version:
- '1.5'
- '1.6'
- '1.7'
- '1.8'
- '1.9'
os:
- ubuntu-latest
- macOS-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1.4.0]
julia-version: [1.9.0]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: '1.5'
version: '1.9'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
Expand Down
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ name = "Mangal"
uuid = "b8b640a6-63d9-51e6-b784-5033db27bef2"
authors = ["Timothée Poisot <timothee.poisot@umontreal.ca>"]
repo-url = "https://github.com/PoisotLab/Mangal.jl.git"
version = "0.4.3"
version = "0.5.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
EcologicalNetworks = "f03a62fe-f8ab-5b77-a061-bb599b765229"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

[compat]
EcologicalNetworks = "0.4, 0.5"
GeoInterface = "1.3"
HTTP = "0.8, 0.9, 1.8"
JSON = "0.21"
julia = "1.5"
julia = "1.5, 1.6, 1.7, 1.8, 1.9"
1 change: 0 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Weave = "44d3d7a6-8a23-5bf8-98c5-b353f8df5ec9"

5 changes: 2 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ _pkg_doc = [
_pkg_vig = [
"Introduction" => "vignettes/introduction.md",
"Counting & paging" => "vignettes/counting.md",
"Network analysis" => "vignettes/ecologicalnetworks.md"
]

_list_of_pages = [
Expand All @@ -34,6 +33,6 @@ makedocs(

deploydocs(
deps = Deps.pip("pygments", "python-markdown-math"),
repo = "github.com/EcoJulia/Mangal.jl.git",
devbranch = "master"
repo = "github.com/PoisotLab/Mangal.jl.git",
devbranch = "main"
)
16 changes: 11 additions & 5 deletions src/Mangal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module Mangal
using HTTP
using JSON
using GeoInterface
using EcologicalNetworks
using Dates
using TestItems

const web_root = "https://mangal.io/"
const api_root = web_root * "api/v2/"
Expand Down Expand Up @@ -86,9 +86,15 @@ include(joinpath(".", "count.jl"))
# Show
include(joinpath(".", "show.jl"))

# EcologicalNetworks wrapper
using EcologicalNetworks: EcologicalNetworks
include(joinpath(".", "ecologicalnetworks.jl"))
export taxonize
@testitem "We can get data in/out of cache" begin
N = nodes()[1]
n = node(N.id)
@test length(Mangal._MANGAL_CACHES[MangalNode]) != 0
end

@testitem "We can get attribute data" begin
@test typeof(attributes()) <: Vector{MangalAttribute}
@test typeof(attribute(6)) <: MangalAttribute
end

end # module
18 changes: 18 additions & 0 deletions src/backbone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,21 @@ function backbone(name::AbstractString)
q = backbones(Pair("name", name))
return isequal(1)(length(q)) ? only(q) : nothing
end


@testitem "We can get data from the backbone" begin
@test typeof(backbones()) <: Vector{MangalReferenceTaxon}
end

@testitem "We can get data from the backbone with a search" begin
@test typeof(backbones("q" => "Salix")) <: Vector{MangalReferenceTaxon}
end

@testitem "We can get specific taxa from the backbone" begin
@test backbone(1).name == "Abutilon theophrasti"
@test backbone("Abutilon theophrasti").id == 1
end

@testitem "We can get paged data from the backbone" begin
@test length(backbones(Pair("count", 10))) == 10
end
17 changes: 17 additions & 0 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ function dataset(name::AbstractString)
q = datasets(Pair("name", name))
return isequal(1)(length(q)) ? only(q) : nothing
end

@testitem "We can get dataset data" begin
@test typeof(datasets()) <: Vector{MangalDataset}

# Datasets with count
count_2 = datasets(Pair("count", 2))
@test typeof(count_2) <: Vector{MangalDataset}
@test length(count_2) == 2

# Dataset by id
@test typeof(dataset(1)) <: MangalDataset

# Dataset by name
@test typeof(dataset("roberson_1929")) <: MangalDataset

@test isnothing(dataset("This_DOESNOT_exist"))
end
118 changes: 0 additions & 118 deletions src/ecologicalnetworks.jl

This file was deleted.

2 changes: 1 addition & 1 deletion src/generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ for mg_type_pair in types_names

Returns the number of $($mg_type) objects that match a query.
"""
function count(::Type{$mg_type}, query::Pair...)
function Base.count(::Type{$mg_type}, query::Pair...)
return Mangal.number_of_objects(Mangal._MANGAL_ENDPOINTS[$mg_type], query...)
end
end
Expand Down
32 changes: 32 additions & 0 deletions src/interaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,35 @@ Returns interactions within a network.
function interactions(n::MangalNetwork, query::Pair...)
return interactions("network_id" => n.id, query...)
end

@testitem "We can get all interactions" begin
@test typeof(interactions()) <: Vector{MangalInteraction}
end

@testitem "We can get all interactions by type" begin
@test typeof(interactions(Pair("type", "mutualism"))) <: Vector{MangalInteraction}
end

@testitem "We can get all interactions to a node" begin
@test typeof(interactions(:, node(31863))) <: Vector{MangalInteraction}
end

@testitem "We can get all interactions from a node" begin
@test typeof(interactions(node(31904), :)) <: Vector{MangalInteraction}
end

@testitem "We can get all interactions to a node by type" begin
@test typeof(interactions(:, node(31863), Pair("type", "predation"))) <: Vector{MangalInteraction}
end

@testitem "We can get all interactions from a node by type" begin
@test typeof(interactions(node(31904), :, Pair("type", "predation"))) <: Vector{MangalInteraction}
end

@testitem "We can get interactions between nodes" begin
@test typeof(interactions(node(31904), node(31863))) <: Vector{MangalInteraction}
end

@testitem "We can get interactions between nodes by type" begin
@test typeof(interactions(node(31904), node(31863), Pair("type", "predation"))) <: Vector{MangalInteraction}
end
4 changes: 4 additions & 0 deletions src/login.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ function login_message()

@info msg
end

@testitem "We can get user data" begin
@test typeof(users()) <: Vector{MangalUser}
end
38 changes: 38 additions & 0 deletions src/network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,41 @@ function network(name::AbstractString)
q = networks(Pair("name", name))
return isequal(1)(length(q)) ? only(q) : nothing
end

@testitem "We can get networks" begin
@test typeof(networks()) <: Vector{MangalNetwork}
end

@testitem "We can get a network by ID" begin
@test typeof(network(19)) <: MangalNetwork
end

@testitem "We can get a network by name" begin
@test typeof(network("howking_1968_19680601_12")) <: MangalNetwork
end

@testitem "We can get a network by dataset" begin
ds = dataset(62)
n_ds = networks(ds)
@test typeof(n_ds) <: Vector{MangalNetwork}
end

@testitem "We can get a network by dataset with additional arguments" begin
ds = dataset(62)
n_ds_q = networks(ds, Pair("count", 2))
@test typeof(n_ds_q) <: Vector{MangalNetwork}
@test length(n_ds_q) == 2
end

@testitem "We can page through multiple network queries" begin
this_page = 1
networks_ponisio = networks(dataset("ponisio_2017"), Pair("count", 10), Pair("page", this_page))
keep_querying = true
while keep_querying
global this_page += 1
response = networks(dataset("ponisio_2017"), Pair("count", 10), Pair("page", this_page))
append!(networks_ponisio, response)
global keep_querying = length(response) > 0
end
@test length(networks_ponisio) == 131
end
23 changes: 23 additions & 0 deletions src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,26 @@ Returns the nodes that are instance of a `MangalReferenceTaxon`, with an additio
function nodes(taxon::MangalReferenceTaxon, query::Pair...)
return nodes(Pair("taxonomy_id", taxon.id), query...)
end

@testitem "We can get node data" begin
@test typeof(nodes()) <: Vector{MangalNode}
end

@testitem "We can get nodes of a network" begin
N1 = network(19)
nN1 = nodes(N1)
@test typeof(nN1) <: Vector{MangalNode}
end


@testitem "We can get taxonomic data in nodes" begin
n1 = node(2158)
@test typeof(n1) <: MangalNode
@test typeof(n1.taxon) <: MangalReferenceTaxon
end

@testitem "We can get nodes from backbone data" begin
b1 = backbone(1)
nb1 = nodes(b1)
@test first(nb1).taxon == b1
end
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[deps]
EcologicalNetworks = "f03a62fe-f8ab-5b77-a061-bb599b765229"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
Loading