Skip to content

Commit

Permalink
rename convert_gt to convert_bgen_gt
Browse files Browse the repository at this point in the history
  • Loading branch information
biona001 committed Feb 7, 2022
1 parent 56b775a commit 3191860
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ function cross_validate(
end

"""
convert_gt(t::Type{T}, b::Bgen)
convert_bgen_gt(t::Type{T}, b::Bgen)
Imports BGEN genotypes and chr/sampleID/pos/snpID/ref/alt into numeric arrays.
Genotypes are centered and scaled to mean 0 variance 1. Missing genotypes will
Expand All @@ -340,7 +340,7 @@ be replaced with the mean. Assumes every variant is biallelic (ie only 1 alt all
# Output
- `G`: matrix of genotypes with type `T`.
"""
function convert_gt(t::Type{T}, b::Bgen) where T <: Real
function convert_bgen_gt(t::Type{T}, b::Bgen) where T <: Real
n = n_samples(b)
p = n_variants(b)

Expand Down Expand Up @@ -428,7 +428,7 @@ will be stored in double precision matrices (64 bit per entry).
"""
function parse_genotypes(tgtfile::AbstractString, dosage=false)
if (endswith(tgtfile, ".vcf") || endswith(tgtfile, ".vcf.gz"))
f = dosage ? VCFTools.convert_ds : VCFTools.convert_gt
f = dosage ? convert_ds : convert_gt
X, X_sampleID, X_chr, X_pos, X_ids, X_ref, X_alt =
f(Float64, tgtfile, trans=false,
save_snp_info=true, msg = "Importing from VCF file...")
Expand All @@ -443,7 +443,7 @@ function parse_genotypes(tgtfile::AbstractString, dosage=false)
tgtfile[1:end-5] * ".sample" : nothing
indexfile = isfile(tgtfile * ".bgi") ? tgtfile * ".bgi" : nothing
bgen = Bgen(tgtfile; sample_path=samplefile, idx_path=indexfile)
X, X_sampleID, X_chr, X_pos, X_ids, X_ref, X_alt = MendelIHT.convert_gt(Float64, bgen)
X, X_sampleID, X_chr, X_pos, X_ids, X_ref, X_alt = MendelIHT.convert_bgen_gt(Float64, bgen)
elseif isplink(tgtfile)
dosage && error("PLINK files detected but dosage = true!")
X = SnpArrays.SnpData(tgtfile)
Expand Down
7 changes: 4 additions & 3 deletions test/wrapper_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ end
rm("cviht.summary.txt", force=true)
rm("iht.summary.txt", force=true)
rm("iht.beta.txt", force=true)
rm("iht.cov.txt", force=true)
catch
println("Unsuccessful deletion of intermediate files generated in" *
" unit tests! Windows users can remove these files manually " *
Expand All @@ -183,14 +184,14 @@ end
@testset "read BGEN and VCF" begin
cd(normpath(MendelIHT.datadir()))
xtrue = convert(Matrix{Float64}, SnpArray("normal.bed"), center=true, scale=true, impute=true)
@time xbgen, _ = MendelIHT.convert_gt(Float64, Bgen("normal.bgen"))
@time xbgen, _ = MendelIHT.convert_bgen_gt(Float64, Bgen("normal.bgen"))
@test all(xbgen .≈ xtrue)
# BGEN wrapper
@time xbgen, X_sampleID, X_chr, X_pos, X_ids, X_ref, X_alt = MendelIHT.parse_genotypes("normal.bgen")
@test all(xbgen .≈ xtrue)
# VCF wrapper
@time xbgen, X_sampleID, X_chr, X_pos, X_ids, X_ref, X_alt = MendelIHT.parse_genotypes("normal.vcf.gz")
@test all(xbgen .≈ xtrue)
@time xvcf, X_sampleID, X_chr, X_pos, X_ids, X_ref, X_alt = MendelIHT.parse_genotypes("normal.vcf.gz")
@test all(xvcf .≈ xtrue)
# Run IHT on wrapper
result_plink = iht("normal", 10, Normal, phenotypes="phenotypes.txt", verbose=true)
result_vcf = iht("normal.vcf.gz", 10, Normal, phenotypes="phenotypes.txt", verbose=true)
Expand Down

2 comments on commit 3191860

@biona001
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 created: JuliaRegistries/General/54117

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 v1.4.4 -m "<description of version>" 31918608a4527410dfd6ac7167b9a761628b1c13
git push origin v1.4.4

Please sign in to comment.