-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
193bb4a
commit deb3026
Showing
10 changed files
with
166 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,8 @@ requirements: | |
- xz | ||
- bzip2 | ||
- lz4-c | ||
# Transfer results | ||
- upload | ||
|
||
test: | ||
commands: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
set -e | ||
|
||
# Use nodejs from build prefix | ||
rm "${PREFIX}/bin/node" | ||
ln -s "${BUILD_PREFIX}/bin/node" "${PREFIX}/bin/node" | ||
|
||
# Don't use pre-built gyp packages | ||
export npm_config_build_from_source=true | ||
|
||
# Ignore custom configuration on build machine | ||
export NPM_CONFIG_USERCONFIG=/tmp/nonexistentrc | ||
|
||
npm install | ||
npm run build | ||
packed=$(npm pack) | ||
npm install --global "${packed}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{% set name = "upload" %} | ||
{% set version = "0.4.1" %} | ||
|
||
package: | ||
name: {{ name }} | ||
version: {{ version }} | ||
|
||
source: | ||
url: https://github.com/hippocampusgirl/{{ name }}/archive/v{{ version }}.tar.gz | ||
sha256: 395f336fa2dc913e84899f1f1fee8a2f57b650f4b6536c079ddba8ca48af7e62 | ||
|
||
build: | ||
noarch: generic | ||
|
||
requirements: | ||
build: | ||
- {{ compiler('c') }} | ||
- {{ compiler('cxx') }} | ||
- nodejs | ||
- make | ||
host: | ||
- nodejs | ||
run: | ||
- nodejs | ||
|
||
test: | ||
requires: | ||
- nodejs | ||
commands: | ||
- upload --help | ||
|
||
about: | ||
home: https://github.com/hippocampusgirl/upload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# -*- coding: utf-8 -*- | ||
import logging | ||
import sys | ||
from argparse import ArgumentParser, Namespace | ||
from multiprocessing import cpu_count | ||
from pathlib import Path | ||
from subprocess import call | ||
from tempfile import TemporaryDirectory | ||
|
||
from ..log import logger, setup_logging | ||
from ..utils import unwrap_which | ||
|
||
upload_executable = unwrap_which("upload") | ||
|
||
path_patterns: list[str] = [ | ||
"chr*.metadata.yaml.gz", | ||
"chr*.score.b2array", | ||
"chr*.score.axis-metadata.pkl.zst", | ||
"covariance.b2array", | ||
"covariance.axis-metadata.pkl.zst", | ||
"populations.pdf", | ||
"*stat-*_statmap.nii.gz", | ||
"*stat-*_statmap.json", | ||
"*mask.nii.gz", | ||
"*mean.nii.gz", | ||
"*std.nii.gz", | ||
"*contrast_matrix.tsv", | ||
] | ||
|
||
|
||
def upload(arguments: Namespace) -> None: | ||
upload_paths: list[Path] = list() | ||
for input_directory_str in arguments.input_directory: | ||
input_directory = Path(input_directory_str).absolute() | ||
for path_pattern in path_patterns: | ||
upload_paths.extend(input_directory.glob(f"**/{path_pattern}")) | ||
|
||
with TemporaryDirectory() as tmp_path_str: | ||
tmp_path = Path(tmp_path_str) | ||
paths: set[str] = set() | ||
for upload_path in upload_paths: | ||
link_path = tmp_path / upload_path.name | ||
link_path.parent.mkdir(parents=True, exist_ok=True) | ||
link_path.symlink_to(upload_path) | ||
paths.add(link_path.name) | ||
|
||
logger.info(f"Uploading {len(paths)} files") | ||
|
||
command: list[str] = [ | ||
upload_executable, | ||
"upload-client", | ||
"--token", | ||
arguments.token, | ||
"--endpoint", | ||
arguments.endpoint, | ||
"--path", | ||
*sorted(paths), | ||
] | ||
if arguments.log_level == "DEBUG": | ||
command.append("--debug") | ||
|
||
logger.debug(f"Running command: {' '.join(command)}") | ||
call(command, cwd=tmp_path) | ||
|
||
|
||
def parse_arguments(argv: list[str]) -> Namespace: | ||
argument_parser = ArgumentParser() | ||
argument_parser.add_argument("--input-directory", nargs="+", required=True) | ||
|
||
argument_parser.add_argument("--token", required=True) | ||
argument_parser.add_argument("--endpoint", default="https://upload.gwas.science") | ||
|
||
# Program options | ||
argument_parser.add_argument( | ||
"--log-level", choices=logging.getLevelNamesMapping().keys(), default="INFO" | ||
) | ||
argument_parser.add_argument("--debug", action="store_true", default=False) | ||
argument_parser.add_argument("--num-threads", type=int, default=cpu_count()) | ||
|
||
return argument_parser.parse_args(argv) | ||
|
||
|
||
def main(): | ||
arguments = parse_arguments(sys.argv[1:]) | ||
setup_logging(level=arguments.log_level) | ||
|
||
try: | ||
upload(arguments) | ||
except Exception as e: | ||
logger.exception("Exception: %s", e, exc_info=True) | ||
if arguments.debug: | ||
import pdb | ||
|
||
pdb.post_mortem() |