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

Add hap-ibd #37057

Merged
merged 2 commits into from
Sep 21, 2022
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
15 changes: 15 additions & 0 deletions recipes/hap-ibd/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -eu -o pipefail

export LD_LIBRARY_PATH="${PREFIX}/lib"

outdir=$PREFIX/share/$PKG_NAME-$PKG_VERSION-$PKG_BUILDNUM
mkdir -p $outdir
mkdir -p $PREFIX/bin

cp hap-ibd.jar $outdir/hap-ibd.jar
cp $RECIPE_DIR/hap-ibd.py $outdir/hap-ibd

ln -s $outdir/hap-ibd $PREFIX/bin
chmod 0755 "${PREFIX}/bin/hap-ibd"
123 changes: 123 additions & 0 deletions recipes/hap-ibd/hap-ibd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python
#
# Wrapper script for Java Conda packages that ensures that the java runtime
# is invoked with the right options. Adapted from the bash script (http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in/246128#246128).

#
# Program Parameters
#
import os
import subprocess
import sys
import shutil
from os import access
from os import getenv
from os import X_OK

jar_file = 'hap-ibd.jar'


default_jvm_mem_opts = ['-Xms2g', '-Xmx4g']

# !!! End of parameter section. No user-serviceable code below this line !!!


def real_dirname(path):
"""Return the symlink-resolved, canonicalized directory-portion of path."""
return os.path.dirname(os.path.realpath(path))


def java_executable():
"""Return the executable name of the Java interpreter."""
java_home = getenv('JAVA_HOME')
java_bin = os.path.join('bin', 'java')

if java_home and access(os.path.join(java_home, java_bin), X_OK):
return os.path.join(java_home, java_bin)
else:
return 'java'


def jvm_opts(argv):
"""Construct list of Java arguments based on our argument list.

The argument list passed in argv must not include the script name.
The return value is a 3-tuple lists of strings of the form:
(memory_options, prop_options, passthrough_options)
"""
mem_opts = []
prop_opts = []
pass_args = []
exec_dir = None

for arg in argv:
if arg.startswith('-D'):
prop_opts.append(arg)
elif arg.startswith('-XX'):
prop_opts.append(arg)
elif arg.startswith('-Xm'):
mem_opts.append(arg)
elif arg.startswith('--exec_dir='):
exec_dir = arg.split('=')[1].strip('"').strip("'")
if not os.path.exists(exec_dir):
shutil.copytree(real_dirname(sys.argv[0]), exec_dir, symlinks=False, ignore=None)
else:
pass_args.append(arg)

# In the original shell script the test coded below read:
# if [ "$jvm_mem_opts" == "" ] && [ -z ${_JAVA_OPTIONS+x} ]
# To reproduce the behaviour of the above shell code fragment
# it is important to explictly check for equality with None
# in the second condition, so a null envar value counts as True!

if mem_opts == [] and getenv('_JAVA_OPTIONS') is None:
mem_opts = default_jvm_mem_opts

return (mem_opts, prop_opts, pass_args, exec_dir)


def def_temp_log_opts(args):
"""
Establish default temporary and log folders.
"""
TEMP = os.getenv("TEMP")

if TEMP is not None:
if '-log' not in args:
args.append('-log')
args.append(TEMP+'/logs')

if '-temp_folder' not in args :
args.append('-temp_folder')
args.append(TEMP)

return args


def main():
java = java_executable()
"""
PeptideShaker updates files relative to the path of the jar file.
In a multiuser setting, the option --exec_dir="exec_dir"
can be used as the location for the peptide-shaker distribution.
If the exec_dir dies not exist,
we copy the jar file, lib, and resources to the exec_dir directory.
"""
(mem_opts, prop_opts, pass_args, exec_dir) = jvm_opts(sys.argv[1:])
pass_args = def_temp_log_opts(pass_args)
jar_dir = exec_dir if exec_dir else real_dirname(sys.argv[0])

if pass_args != [] and pass_args[0].startswith('eu'):
jar_arg = '-cp'
else:
jar_arg = '-jar'

jar_path = os.path.join(jar_dir, jar_file)

java_args = [java] + mem_opts + prop_opts + [jar_arg] + [jar_path] + pass_args

sys.exit(subprocess.call(java_args))


if __name__ == '__main__':
main()
35 changes: 35 additions & 0 deletions recipes/hap-ibd/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{% set name = "hap-ibd" %}
{% set version = "1.0.rev20May22.818" %}
{% set sha256 = "d140accd58e9dbf5402ba66b691074ff858b454f8a1d4f2dc4ccd1ee23730e49" %}

package:
name: {{ name }}
version: {{ version }}

source:
url: https://faculty.washington.edu/browning/hap-ibd.jar
sha256: {{ sha256 }}

build:
number: 0
noarch: generic

requirements:
run:
- openjdk >=8
- python

test:
commands:
- "hap-ibd"

about:
home: https://github.com/browning-lab/hap-ibd
license: Apache-2.0
summary: "Hap-ibd Detects identity-by-descent (IBD) segments and homozygosity-by-descent (HBD) segments in phased genotype data."
doc_url: https://github.com/browning-lab/hap-ibd/blob/master/README.md

extra:
identifiers:
- biotools:hap-ibd
- doi:10.1016/j.ajhg.2020.02.010