Skip to content

Commit

Permalink
Merge pull request #36 from senresearch/dev
Browse files Browse the repository at this point in the history
update to v0.3.0
  • Loading branch information
GregFa authored Jun 16, 2023
2 parents 02ac924 + a922ce7 commit 4850923
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GeneNetworkAPI"
uuid = "5ef98721-7938-4c15-bad2-60f0fa16d62a"
authors = ["Chelsea Trotter <chelsea.xhu@gmail.com>", "Gregory Farage <gfarage@uthsc.edu>", "Saunak Sen <sen@uthsc.edu>"]
version = "0.2.0"
version = "0.3.0"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ julia> GeneNetworkAPI.subset(list_species(), :Name => x->x.=="rat")
## List groups for a species

Since the information is organized by segregating population
("group"), it is useful to get a list for a preticular species you
("group"), it is useful to get a list for a particular species you
might be interested in.

```
Expand Down
5 changes: 4 additions & 1 deletion src/GeneNetworkAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module GeneNetworkAPI
include("./info_data.jl")
export info_dataset, info_pheno

include("./download_data.jl")
export download_geno, download_pheno, download_omics

include("./get_data.jl")
export get_geno, get_pheno, get_omics

Expand All @@ -23,7 +26,7 @@ module GeneNetworkAPI
export show_table

include("./utils_geno.jl")
export parse_geno, genofile_location
export parse_geno, genofile_location, has_genofile_meta

include("./utils.jl")
export make_rectangular, has_error_500
Expand Down
90 changes: 90 additions & 0 deletions src/download_data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# This file contains the functions to download data from gene network APIs

##############################
# Functions downloading data #
##############################

#############
# Geno data #
#############
"""
download_geno(group::String,format::String="geno";
gn_url::String=gn_url(),
path::String = "")
Download the genotype matrix for a `group` in a given `format`.
Currently works only for files in the `geno` format.
The file will be downloaded in `path` location, if `path` is not specified, then
the file will be a temporary file.
"""
function download_geno(group, format = "geno";
gn_url::String = gn_url(),
path::String = tempname())

if has_genofile_meta(group; gn_url = gn_url)
# need to check real location of data
vlocation = genofile_location(group; gn_url = gn_url)

if length(vlocation) == 1
group = vlocation[1][1:end-5] # expect ".geno" extension
# else
# println("Info: group ", group, " has additional genotype files, see locations")
# show_table(list_geno(group; gn_url=gn_url))
end
end

# increase timeout response from the server
downloader = Downloads.Downloader()
downloader.easy_hook = (easy, info) -> Downloads.Curl.setopt(easy, Downloads.Curl.CURLOPT_LOW_SPEED_TIME, 300)

geno_url = gn_url * "genotypes/" * group * "." * format

return Downloads.download(geno_url, path; downloader = downloader)
end

##############
# Pheno data #
##############

"""
download_pheno(dataset::String;gn_url::String=gn_url())
Downloads the non-omic ("clinical") phenotypes for a given `dataset`.
The file will be downloaded in `path` location, if `path` is not specified, then
the file will be a temporary file.
"""
function download_pheno(dataset::String;
gn_url::String=gn_url(),
path::String = tempname())
pheno_url = gn_url * "sample_data" * "/" * dataset * "Publish"
return Downloads.download(pheno_url, path)
end

##############
# Omics data #
##############


"""
download_omics(dataset::String;
gn_url::String=gn_url(),
path::String = tempname())
Download the omic phenotypes for a given `dataset`.
The file will be downloaded in `path` location, if `path` is not specified, then
the file will be a temporary file.
"""
function download_omics(dataset::String;
gn_url::String=gn_url(),
path::String = tempname())
# increase timeout response from the server
downloader = Downloads.Downloader();
downloader.easy_hook = (easy, info) -> Downloads.Curl.setopt(easy, Downloads.Curl.CURLOPT_LOW_SPEED_TIME, 300);

omics_url = gn_url * "sample_data" * "/" * dataset

return Downloads.download(omics_url, path; downloader=downloader)
end
46 changes: 13 additions & 33 deletions src/get_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,9 @@ Currently works only for files in the `geno` format.
"""
function get_geno(group, format="geno"; gn_url::String=gn_url())

if has_genofile_meta(group; gn_url=gn_url)
# need to check real location of data
vlocation = genofile_location(group; gn_url=gn_url)

if length(vlocation) == 1
group = vlocation[1][1:end-5] # expect ".geno" extension
# else
# println("Info: group ", group, " has additional genotype files, see locations")
# show_table(list_geno(group; gn_url=gn_url))
end
end

# increase timeout response from the server
downloader = Downloads.Downloader();
downloader.easy_hook = (easy, info) -> Downloads.Curl.setopt(easy, Downloads.Curl.CURLOPT_LOW_SPEED_TIME, 300);

geno_url = gn_url * "genotypes/" * group * "." * format
geno = parse_geno(Downloads.download(geno_url; downloader=downloader))
geno_file = download_geno(group, format;gn_url = gn_url)

geno = parse_geno(geno_file)

return geno
end
Expand All @@ -47,17 +32,18 @@ end
get_pheno(dataset::String;gn_url::String=gn_url())
Returns the non-omic ("clinical") phenotypes for a given `dataset`.
"""
function get_pheno(dataset::String; gn_url::String=gn_url())
url = gn_url * "sample_data" * "/" * dataset * "Publish"
return CSV.read(Downloads.download(url), DataFrame, delim=',',missingstring="x")
end
"""
get_pheno(group::String,trait::String="geno";gn_url::String=gn_url())
---
get_pheno(dataset::String,trait::String; gn_url::String=gn_url())
Returns a given `trait` in a `group`.
"""
function get_pheno(dataset::String; gn_url::String=gn_url())
pheno_file = download_pheno(dataset; gn_url = gn_url)
return CSV.read(pheno_file, DataFrame, delim=',',missingstring="x")
end

function get_pheno(dataset::String,trait::String; gn_url::String=gn_url())
url = gn_url * "sample_data" * "/" * dataset * "/" * trait
return json2df(get_api(url))
Expand All @@ -68,18 +54,12 @@ end
# Omics data #
##############


"""
get_omics(dataset::String;gn_url::String=gn_url())
Returns the omic phenotypes for a given `dataset`.
"""
function get_omics(dataset::String; gn_url::String=gn_url())
# increase timeout response from the server
downloader = Downloads.Downloader();
downloader.easy_hook = (easy, info) -> Downloads.Curl.setopt(easy, Downloads.Curl.CURLOPT_LOW_SPEED_TIME, 300);

omics_url = gn_url * "sample_data" * "/" * dataset

return CSV.read(Downloads.download(omics_url; downloader=downloader), DataFrame, delim=',',missingstring="x")
omics_file = download_omics(dataset; gn_url= gn_url)
return CSV.read(omics_file, DataFrame, delim=',',missingstring="x")
end
30 changes: 30 additions & 0 deletions test/gnAPI_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,33 @@ dfRslt1 = GeneNetworkAPI.select(filter(row->row.trait == 12762, dfRslt), [2,3,4]

println("Get correlation test 10: ", @test (dfRslt1 == dfCorrelation));

#########################
# TEST 11 download geno #
#########################

file_downloaded = download_geno("BXD", path = "BXD_raw.geno");

println("Download geno file test 11: ", @test (isfile(file_downloaded)));

rm(file_downloaded)


##########################
# TEST 12 download pheno #
##########################

file_downloaded = download_pheno("HSNIH-Palmer", path = "HSNIH-Palmer.csv");

println("Download pheno file test 12: ", @test (isfile(file_downloaded)));

rm(file_downloaded)

##########################
# TEST 13 download omics #
##########################

file_downloaded = download_omics("INIA_AmgCoh_0311");

println("Download pheno file test 13: ", @test (isfile(file_downloaded)));

rm(file_downloaded)

2 comments on commit 4850923

@GregFa
Copy link
Member Author

@GregFa GregFa commented on 4850923 Jun 16, 2023

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 created: JuliaRegistries/General/85754

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.3.0 -m "<description of version>" 485092392310fce3ad65c06e8626c1c5b2c2312b
git push origin v0.3.0

Please sign in to comment.