Skip to content

Commit

Permalink
Fix hashing bug (regression)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjotrp committed Jan 21, 2022
1 parent f19f363 commit 6b7831b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .guix-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ echo gemma-wrapper --force --json \
-a test/data/input/BXD_snps.txt \
-gk

env GUIX_PACKAGE_PATH=~/guix-bioinformatics guix environment guix --ad-hoc ruby gemma-gn2 parallel which vim less
guix shell -L ~/guix-bioinformatics -C ruby gemma-gn2 parallel which vim less
36 changes: 19 additions & 17 deletions bin/gemma-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Author:: Pjotr Prins
# License:: GPL3
#
# Copyright (C) 2017-2021 Pjotr Prins <[email protected]>
# Copyright (C) 2017-2022 Pjotr Prins <[email protected]>

USAGE = "
GEMMA wrapper example:
Expand Down Expand Up @@ -64,6 +64,7 @@ if not gemma_command
end
end

hashme = nil

require 'digest/sha1'
require 'fileutils'
Expand Down Expand Up @@ -214,13 +215,13 @@ end
# ---- Start banner

GEMMA_K_VERSION=version
GEMMA_K_BANNER = "gemma-wrapper #{version} (Ruby #{RUBY_VERSION}) by Pjotr Prins 2017-2021\n"
GEMMA_K_BANNER = "gemma-wrapper #{version} (Ruby #{RUBY_VERSION}) by Pjotr Prins 2017-2022\n"
info.call GEMMA_K_BANNER

# Check gemma version
begin
gemma_command2 = options[:gemma_command]
info.call "NOTE: gemma-wrapper is soon to be replaced by gemma2/lib"
info.call "NOTE: gemma-wrapper is soon to be replaced"

GEMMA_INFO = `#{gemma_command2}`
rescue Errno::ENOENT
Expand Down Expand Up @@ -279,7 +280,6 @@ raise "Expected GEMMA -a genotype file switch" if anno_idx == nil
CHROMOSOMES = get_chromosomes(gemma_args[anno_idx+1])

# ---- Compute HASH on inputs
hashme = []
geno_idx = gemma_args.index '-g'
raise "Expected GEMMA -g genotype file switch" if geno_idx == nil
pheno_idx = gemma_args.index '-p'
Expand Down Expand Up @@ -309,14 +309,15 @@ execute = lambda { |cmd|

compute_hash = lambda do | phenofn = nil |
# Compute a HASH on the inputs
debug.call "Hashing on ",hashme,"\n"
error.call "Hash is empty" if hashme == nil or hashme == []
debug.call "Hashing on ",hashme," before phenofn inject"
hashes = []
hm = if phenofn
hashme + ["-p", phenofn]
else
hashme
end
debug.call(hm)
debug.call("Hashing on ",hm)
hm.each do | item |
if File.file?(item)
hashes << Digest::SHA1.hexdigest(File.read(item))
Expand All @@ -329,6 +330,18 @@ compute_hash = lambda do | phenofn = nil |
Digest::SHA1.hexdigest hashes.join(' ')
end

error.call "Do not use the GEMMA -o switch!" if gemma_args.include? '-o'
error.call "Do not use the GEMMA -outdir switch!" if gemma_args.include? '-outdir'
GEMMA_ARGS_HASH = gemma_args.dup # do not include outdir

hashme =
if DO_COMPUTE_KINSHIP and pheno_idx != nil
# Remove the phenotype file from the hash for GRM computation
GEMMA_ARGS_HASH[0..pheno_idx-1] + GEMMA_ARGS_HASH[pheno_idx+2..-1]
else
GEMMA_ARGS_HASH
end

HASH = compute_hash.call()
options[:hash] = HASH

Expand All @@ -345,21 +358,10 @@ FileUtils::mkdir_p options[:cache_dir]

Dir.mktmpdir do |tmpdir| # tmpdir for GEMMA output

error.call "Do not use the GEMMA -o switch!" if gemma_args.include? '-o'
error.call "Do not use the GEMMA -outdir switch!" if gemma_args.include? '-outdir'
GEMMA_ARGS_HASH = gemma_args.dup # do not include outdir
gemma_args << '-outdir'
gemma_args << tmpdir
GEMMA_ARGS = gemma_args

hashme =
if DO_COMPUTE_KINSHIP and pheno_idx != nil
# Remove the phenotype file from the hash for GRM computation
GEMMA_ARGS_HASH[0..pheno_idx-1] + GEMMA_ARGS_HASH[pheno_idx+2..-1]
else
GEMMA_ARGS_HASH
end

debug.call "Options: ",options,"\n" if !options[:quiet]

invoke_gemma = lambda do |extra_args, cache_hit = false, chr = "full", permutation = 1|
Expand Down

0 comments on commit 6b7831b

Please sign in to comment.