jamofetch 3.7.7__tar.gz → 3.7.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jamofetch
3
- Version: 3.7.7
3
+ Version: 3.7.8
4
4
  Summary: A thin wrapper to retrieve sequence from JAMO at NERSC and on Dori.
5
5
  Author: Duncan Scott
6
6
  Requires-Python: >=3.9
@@ -89,15 +89,15 @@ options:
89
89
  (venv) [dnscott@ln005 jamofetch]$ jamofetch -d data -l NPUNN -l NOOHG -l HOGH -w --max -1
90
90
  fetching sequence:
91
91
 
92
- apptainer --silent run docker://doejgi/jamo-dori jamo link -s dori library NPUNN
92
+ apptainer --silent exec docker://doejgi/jamo-dori jamo link -s dori custom '{"metadata.library_name":"NPUNN","metadata.fastq_type":"sdm_normal","group":"sdm"}'
93
93
  NPUNN /global/dna/dm_archive/sdm/pacbio/00/27/47/pbio-2747.27352.bc1001_BAK8A_OA--bc1001_BAK8A_OA.ccs.fastq.gz BACKUP_COMPLETE 6391936239a7711d789a9380
94
94
  NPUNN /clusterfs/jgi/groups/dsi/homes/dnscott/git/jamofetch/data/NPUNN.pbio-2747.27352.bc1001_BAK8A_OA--bc1001_BAK8A_OA.ccs.fastq.gz
95
95
 
96
- apptainer --silent run docker://doejgi/jamo-dori jamo link -s dori library NOOHG
96
+ apptainer --silent exec docker://doejgi/jamo-dori jamo link -s dori custom '{"metadata.library_name":"NOOHG","metadata.fastq_type":"sdm_normal","group":"sdm"}'
97
97
  NOOHG /global/dna/dm_archive/sdm/pacbio/00/26/91/pbio-2691.26653.bc1001_BAK8A_OA--bc1001_BAK8A_OA.ccs.fastq.gz RESTORED 6347dbb35bc59487d7e768d6
98
98
  NOOHG /clusterfs/jgi/groups/dsi/homes/dnscott/git/jamofetch/data/NOOHG.pbio-2691.26653.bc1001_BAK8A_OA--bc1001_BAK8A_OA.ccs.fastq.gz
99
99
 
100
- apptainer --silent run docker://doejgi/jamo-dori jamo link -s dori library HOGH
100
+ apptainer --silent exec docker://doejgi/jamo-dori jamo link -s dori custom '{"metadata.library_name":"HOGH","metadata.fastq_type":"sdm_normal","group":"sdm"}'
101
101
  HOGH /global/dna/dm_archive/sdm/illumina/00/63/97/6397.2.44053.GGCTAC.fastq.gz RESTORED 51d52a82067c014cd6ef4f6f
102
102
  HOGH /clusterfs/jgi/groups/dsi/homes/dnscott/git/jamofetch/data/HOGH.6397.2.44053.GGCTAC.fastq.gz
103
103
 
@@ -78,15 +78,15 @@ options:
78
78
  (venv) [dnscott@ln005 jamofetch]$ jamofetch -d data -l NPUNN -l NOOHG -l HOGH -w --max -1
79
79
  fetching sequence:
80
80
 
81
- apptainer --silent run docker://doejgi/jamo-dori jamo link -s dori library NPUNN
81
+ apptainer --silent exec docker://doejgi/jamo-dori jamo link -s dori custom '{"metadata.library_name":"NPUNN","metadata.fastq_type":"sdm_normal","group":"sdm"}'
82
82
  NPUNN /global/dna/dm_archive/sdm/pacbio/00/27/47/pbio-2747.27352.bc1001_BAK8A_OA--bc1001_BAK8A_OA.ccs.fastq.gz BACKUP_COMPLETE 6391936239a7711d789a9380
83
83
  NPUNN /clusterfs/jgi/groups/dsi/homes/dnscott/git/jamofetch/data/NPUNN.pbio-2747.27352.bc1001_BAK8A_OA--bc1001_BAK8A_OA.ccs.fastq.gz
84
84
 
85
- apptainer --silent run docker://doejgi/jamo-dori jamo link -s dori library NOOHG
85
+ apptainer --silent exec docker://doejgi/jamo-dori jamo link -s dori custom '{"metadata.library_name":"NOOHG","metadata.fastq_type":"sdm_normal","group":"sdm"}'
86
86
  NOOHG /global/dna/dm_archive/sdm/pacbio/00/26/91/pbio-2691.26653.bc1001_BAK8A_OA--bc1001_BAK8A_OA.ccs.fastq.gz RESTORED 6347dbb35bc59487d7e768d6
87
87
  NOOHG /clusterfs/jgi/groups/dsi/homes/dnscott/git/jamofetch/data/NOOHG.pbio-2691.26653.bc1001_BAK8A_OA--bc1001_BAK8A_OA.ccs.fastq.gz
88
88
 
89
- apptainer --silent run docker://doejgi/jamo-dori jamo link -s dori library HOGH
89
+ apptainer --silent exec docker://doejgi/jamo-dori jamo link -s dori custom '{"metadata.library_name":"HOGH","metadata.fastq_type":"sdm_normal","group":"sdm"}'
90
90
  HOGH /global/dna/dm_archive/sdm/illumina/00/63/97/6397.2.44053.GGCTAC.fastq.gz RESTORED 51d52a82067c014cd6ef4f6f
91
91
  HOGH /clusterfs/jgi/groups/dsi/homes/dnscott/git/jamofetch/data/HOGH.6397.2.44053.GGCTAC.fastq.gz
92
92
 
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
4
4
 
5
5
  [project]
6
6
  name = "jamofetch"
7
- version = "3.7.7"
7
+ version = "3.7.8"
8
8
  description = "A thin wrapper to retrieve sequence from JAMO at NERSC and on Dori."
9
9
  authors = [{ name = "Duncan Scott" }]
10
10
  readme = "README.md"
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env python3
2
2
 
3
+ import json
3
4
  import logging
4
5
  import os
5
6
  import pathlib
@@ -10,17 +11,43 @@ import time
10
11
  from argparse import ArgumentParser
11
12
  from stat import ST_CTIME
12
13
 
13
- JAMO_CMD_NERSC = 'module load jamo; jamo link library'
14
- JAMO_CMD_DORI = 'apptainer --silent run docker://doejgi/jamo-dori jamo link -s dori library'
14
+ # Base commands; get_cmd() appends the query.
15
+ #
16
+ # Dori uses `apptainer exec`, not `run`: the jamo-dori image's runscript strips the
17
+ # double quotes out of the JSON query, and jamo then fails with a JSONDecodeError.
18
+ JAMO_CMD_NERSC = 'module load jamo; jamo link'
19
+ JAMO_CMD_DORI = 'apptainer --silent exec docker://doejgi/jamo-dori jamo link -s dori'
15
20
 
16
21
  TWO_HOURS = 7200 # seconds
17
22
  ONE_MINUTE = 60 # seconds
18
23
 
19
24
 
20
25
  def get_cmd(clean_lib_name) -> str:
21
- if os.getenv('SLURM_PARTITION') == 'dori':
22
- return f"{JAMO_CMD_DORI} {clean_lib_name}"
23
- return f"{JAMO_CMD_NERSC} {clean_lib_name}"
26
+ """
27
+ Build the site-appropriate `jamo link` command for a library's SDM fastq.
28
+
29
+ Uses a custom query rather than `jamo link library <name>`. That form applies
30
+ jamo's default `raw_normal` filter, {'metadata.fastq_type': 'sdm_normal',
31
+ 'user': 'sdm'}, and files from SDM's newer pipeline are owned by user
32
+ 'sdm_pipeline' (group still 'sdm'), so it matched nothing for them. Filtering
33
+ on group instead of user matches both.
34
+
35
+ Key order matters: jamo names each symlink '<first string-valued query key's
36
+ value>.<file_name>', so metadata.library_name must stay first or
37
+ _find_fastq_path() will not find the link.
38
+
39
+ A library sequenced on more than one run matches one fastq per run; nothing
40
+ here chooses between them.
41
+ """
42
+ # Validated because the name is interpolated into a shell command.
43
+ lib_name = _clean_library_name(clean_lib_name)
44
+ query = json.dumps({
45
+ "metadata.library_name": lib_name,
46
+ "metadata.fastq_type": "sdm_normal",
47
+ "group": "sdm",
48
+ }, separators=(',', ':'))
49
+ base = JAMO_CMD_DORI if os.getenv('SLURM_PARTITION') == 'dori' else JAMO_CMD_NERSC
50
+ return f"{base} custom '{query}'"
24
51
 
25
52
 
26
53
  def _clean_library_name(library_name):
@@ -0,0 +1,47 @@
1
+ import json
2
+ import shlex
3
+
4
+ import pytest
5
+
6
+ from jamofetch import jamofetch
7
+
8
+
9
+ def _query(cmd):
10
+ # The query is the single-quoted final argument; shlex undoes the shell quoting.
11
+ return json.loads(shlex.split(cmd)[-1])
12
+
13
+
14
+ def test_nersc_cmd(monkeypatch):
15
+ monkeypatch.delenv('SLURM_PARTITION', raising=False)
16
+ cmd = jamofetch.get_cmd('LBBDHFZ')
17
+ assert cmd.startswith('module load jamo; jamo link custom ')
18
+ assert _query(cmd) == {
19
+ "metadata.library_name": "LBBDHFZ",
20
+ "metadata.fastq_type": "sdm_normal",
21
+ "group": "sdm",
22
+ }
23
+
24
+
25
+ def test_dori_cmd_uses_exec(monkeypatch):
26
+ monkeypatch.setenv('SLURM_PARTITION', 'dori')
27
+ cmd = jamofetch.get_cmd('LBBDHFZ')
28
+ assert cmd.startswith('apptainer --silent exec docker://doejgi/jamo-dori jamo link -s dori custom ')
29
+ assert _query(cmd)["metadata.library_name"] == "LBBDHFZ"
30
+
31
+
32
+ def test_library_name_is_first_query_key(monkeypatch):
33
+ # jamo names the symlink after the first string-valued key; _find_fastq_path
34
+ # relies on that being the library name.
35
+ monkeypatch.delenv('SLURM_PARTITION', raising=False)
36
+ assert next(iter(_query(jamofetch.get_cmd('LBBDHFZ')))) == "metadata.library_name"
37
+
38
+
39
+ def test_query_does_not_filter_on_user(monkeypatch):
40
+ monkeypatch.delenv('SLURM_PARTITION', raising=False)
41
+ assert "user" not in _query(jamofetch.get_cmd('LBBDHFZ'))
42
+
43
+
44
+ @pytest.mark.parametrize('bad', ["LBB'DHFZ", 'lbbdhfz', 'LBB DHFZ', 'LBB;rm'])
45
+ def test_invalid_library_name_rejected(bad):
46
+ with pytest.raises(ValueError):
47
+ jamofetch.get_cmd(bad)
@@ -1,2 +0,0 @@
1
- from jamofetch import jamofetch
2
-
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes