Skip to content

Commit 5cecfa5

Browse files
Michele BerselliMichele Berselli
authored andcommitted
added docs and fixed arg error in create_metawfr, ff_key was missing
1 parent f7b3e67 commit 5cecfa5

File tree

4 files changed

+138
-12
lines changed

4 files changed

+138
-12
lines changed

_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Version information."""
22

33
# The following line *must* be the last in the module, exactly as formatted:
4-
__version__ = "0.2.2"
4+
__version__ = "0.2.3"

docs/ff_functions.rst

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,154 @@
22
FF_functions
33
============
44

5+
create_metawfr
6+
**************
7+
8+
Function to create a meta-workflow-run json structure for case from case metadata.
9+
Return json structure for the meta-workflow-run.
10+
Can automatically post the meta-workflow-run as *MetaWorkflowRun* object on the portal and patch ``meta_workflow_run`` key for case with the new uuid.
11+
12+
``create_metawfr_from_case(metawf_uuid<str>, case_uuid<str>, type<str>, ff_key<key>, post=False, patch_case=False, verbose=False)``
13+
14+
.. code-block:: python
15+
16+
from magma_ff import create_metawfr
17+
18+
# UUIDs
19+
metawf_uuid = '' # uuid for meta-workflow
20+
case_uuid = '' # uuid for the case
21+
22+
# Post | Patch
23+
# post=True to automatically post a new MetaWorkflowRun object on the portal
24+
# patch_case=True to update meta_workflow_run for case with uuid for new meta-workflow-run
25+
26+
# type
27+
# 'WGS trio', 'WGS proband', 'WGS cram proband'
28+
type = 'WGS trio'
29+
30+
# ff_key
31+
# -> key generated by ff_utils to authenticate on the portal
32+
33+
metawfr_json = create_metawfr.create_metawfr_from_case(metawf_uuid, case_uuid, type, ff_key, post=False, patch_case=False, verbose=False)
34+
35+
536
run_metawfr
637
***********
738

839
Function to run workflow-runs in meta-workflow-run.
940
Calculates which workflow-runs are ready to run, starts the run with tibanna and patch the metadata.
1041

11-
``run_metawfr(metawfr_uuid<str>, ff_key<key>, verbose=False, sfn='tibanna_zebra', env='fourfront-cgap')``
42+
``run_metawfr(metawfr_uuid<str>, ff_key<key>, verbose=False, sfn='tibanna_zebra', env='fourfront-cgap', maxcount=None)``
1243

1344
.. code-block:: python
1445
46+
from magma_ff import run_metawfr
47+
48+
# UUIDs
49+
metawfr_uuid = '' # uuid for meta-workflow-run
50+
51+
# ff_key
52+
# -> key generated by ff_utils to authenticate on the portal
53+
54+
# env
55+
# environment to use to access metadata
56+
env = 'fourfront-cgap'
57+
58+
# sfn
59+
# step function to use for tibanna
60+
sfn = 'tibanna_zebra'
61+
62+
run_metawfr.run_metawfr(metawfr_uuid, ff_key, verbose=False, sfn='tibanna_zebra', env='fourfront-cgap', maxcount=None)
1563
1664
1765
status_metawfr
1866
**************
1967

2068
Function to check and patch status for workflow-runs in meta-workflow-run that are running.
69+
Update the status to ``completed`` or ``failed`` for finished runs.
2170

2271
``status_metawfr(metawfr_uuid<str>, ff_key<key>, verbose=False, env='fourfront-cgap')``
2372

2473
.. code-block:: python
2574
75+
from magma_ff import status_metawfr
76+
77+
# UUIDs
78+
metawfr_uuid = '' # uuid for meta-workflow-run
79+
80+
# ff_key
81+
# -> key generated by ff_utils to authenticate on the portal
82+
83+
# env
84+
# environment to use to access metadata
85+
env = 'fourfront-cgap'
86+
87+
status_metawfr.status_metawfr(metawfr_uuid, ff_key, verbose=False, env=env)
2688
2789
2890
import_metawfr
2991
**************
3092

31-
Function to import metadata for meta-workflow-run from a different meta-workflow-run.
93+
Creates a new meta-workflow-run json structure for case using specified ``create_metawfr`` function.
94+
Imports information from different meta-workflow-run specified as ``metawfr_uuid`` for steps that are listed in ``steps_name``.
95+
Return json structure for the new meta-workflow-run.
96+
Can automatically post the new meta-workflow-run as *MetaWorkflowRun* object on the portal.
3297

33-
``import_metawfr(metawf_uuid<str>, metawfr_uuid<str>, case_uuid<str>, steps_name<str list>, create_metawfr<function>, ff_key<key>, post=False, verbose=False)``
98+
``import_metawfr(metawf_uuid<str>, metawfr_uuid<str>, case_uuid<str>, steps_name<str list>, create_metawfr<function>, type<str>, ff_key<key>, post=False, verbose=False)``
3499

35100
.. code-block:: python
101+
102+
from magma_ff import import_metawfr
103+
from magma_ff import create_metawfr
104+
105+
# UUIDs
106+
metawf_uuid = '' # uuid for meta-workflow
107+
metawfr_uuid = '' # uuid for old meta-workflow-run to import
108+
case_uuid = '' # uuid for the case
109+
110+
# Post
111+
# post=True to automatically post a new MetaWorkflowRun object on the portal
112+
113+
# ff_key
114+
# -> key generated by ff_utils to authenticate on the portal
115+
116+
# type
117+
# 'WGS trio', 'WGS proband', 'WGS cram proband'
118+
type = 'WGS trio'
119+
120+
# steps_name
121+
steps_name = ['workflow_granite-mpileupCounts', 'workflow_gatk-ApplyBQSR-check']
122+
123+
# create_metawfr
124+
# function to use to create a new meta-workflow-run structure from case
125+
# e.g. create_metawfr.create_metawfr_from_case
126+
127+
metawfr_json = import_metawfr.import_metawfr(metawf_uuid, metawfr_uuid, case_uuid, steps_name, create_metawfr.create_metawfr_from_case, type, ff_key)
128+
129+
130+
reset_metawfr
131+
*************
132+
133+
Re-set workflow-runs in meta-workflow-run that correspond to a step defined in ``step_name`` and with status in ``status``.
134+
135+
``reset_status(metawfr_uuid<str>, status<str | str list>, step_name<str | str list>, ff_key<key>, verbose=False)``
136+
137+
.. code-block:: python
138+
139+
from magma_ff import reset_metawfr
140+
141+
# UUIDs
142+
metawfr_uuid = '' # uuid for meta-workflow-run
143+
144+
# ff_key
145+
# -> key generated by ff_utils to authenticate on the portal
146+
147+
# step_name
148+
# name or list of names for step-workflows that need to be reset
149+
step_name = ['workflow_granite-mpileupCounts', 'workflow_gatk-ApplyBQSR-check']
150+
151+
# status
152+
# status or list of status to reset
153+
status = 'failed' # running | completed | failed
154+
155+
reset_metawfr.reset_status(metawfr_uuid, status, step_name, ff_key, verbose=False)

magma_ff/create_metawfr.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def create_metawfr_from_case(metawf_uuid, case_uuid, type, ff_key, post=False, p
1919

2020
if type == 'WGS cram proband':
2121
pedigree = pedigree[0:1]
22-
input = create_metawfr_input_from_pedigree_proband_only(pedigree)
22+
input = create_metawfr_input_from_pedigree_proband_only(pedigree, ff_key)
2323
elif type == 'WGS proband':
2424
pedigree = pedigree[0:1]
25-
input = create_metawfr_input_from_pedigree_proband_only(pedigree)
25+
input = create_metawfr_input_from_pedigree_proband_only(pedigree, ff_key)
2626
elif type == 'WGS trio':
27-
input = create_metawfr_input_from_pedigree_trio(pedigree)
27+
input = create_metawfr_input_from_pedigree_trio(pedigree, ff_key)
2828

29-
metawfr = create_metawfr_from_input(input, metawf_uuid, case_meta)
29+
metawfr = create_metawfr_from_input(input, metawf_uuid, case_meta, ff_key)
3030

3131
# post meta-wfr
3232
if post:
@@ -40,10 +40,11 @@ def create_metawfr_from_case(metawf_uuid, case_uuid, type, ff_key, post=False, p
4040
res_patch = ff_utils.patch_metadata({'meta_workflow_run': metawfr['uuid']}, case_uuid, key=ff_key)
4141
if verbose:
4242
print(res_patch)
43+
4344
return metawfr
4445

4546

46-
def create_metawfr_from_input(metawfr_input, metawf_uuid, case_meta):
47+
def create_metawfr_from_input(metawfr_input, metawf_uuid, case_meta, ff_key):
4748
metawf_meta = ff_utils.get_metadata(metawf_uuid, add_on='?frame=raw&datastore=database', key=ff_key)
4849
metawfr = {'meta_workflow': metawf_uuid,
4950
'input': metawfr_input,
@@ -71,7 +72,7 @@ def create_metawfr_from_input(metawfr_input, metawf_uuid, case_meta):
7172
return metawfr
7273

7374

74-
def create_metawfr_input_from_pedigree_cram_proband_only(pedigree):
75+
def create_metawfr_input_from_pedigree_cram_proband_only(pedigree, ff_key):
7576
sample = pedigree[0]
7677
sample_acc = sample['sample_accession']
7778
sample_meta = ff_utils.get_metadata(sample_acc, add_on='?frame=raw&datastore=database', key=ff_key)
@@ -97,7 +98,7 @@ def create_metawfr_input_from_pedigree_cram_proband_only(pedigree):
9798
return input
9899

99100

100-
def create_metawfr_input_from_pedigree_proband_only(pedigree):
101+
def create_metawfr_input_from_pedigree_proband_only(pedigree, ff_key):
101102
sample = pedigree[0]
102103
sample_acc = sample['sample_accession']
103104
sample_meta = ff_utils.get_metadata(sample_acc, add_on='?frame=raw&datastore=database', key=ff_key)
@@ -140,7 +141,7 @@ def create_metawfr_input_from_pedigree_proband_only(pedigree):
140141
return input
141142

142143

143-
def create_metawfr_input_from_pedigree_trio(pedigree):
144+
def create_metawfr_input_from_pedigree_trio(pedigree, ff_key):
144145
# prepare fastq input
145146
r1_uuids_fam = []
146147
r2_uuids_fam = []
@@ -195,6 +196,7 @@ def create_metawfr_input_from_pedigree_trio(pedigree):
195196
def sort_pedigree(pedigree):
196197
sorted_pedigree = sorted(pedigree, key=lambda x: x['relationship'] != 'proband') # make it proband-first
197198
sorted_pedigree[1:] = sorted(sorted_pedigree[1:], key=lambda x: x['relationship'] not in ['mother','father']) # parents next
199+
198200
return sorted_pedigree
199201

200202

@@ -213,6 +215,7 @@ def pedigree_to_qc_pedigree(samples_pedigree):
213215
'sample_name': sample.get('sample_name', '')
214216
}
215217
qc_pedigree.append(member_qc_pedigree)
218+
216219
return qc_pedigree
217220

218221

@@ -222,4 +225,5 @@ def remove_parents_without_sample(samples_pedigree):
222225
parents = a_member['parents']
223226
new_parents = [i for i in parents if i in individuals]
224227
a_member['parents'] = new_parents
228+
225229
return samples_pedigree

magma_ff/import_metawfr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ def import_metawfr(metawf_uuid, metawfr_uuid, case_uuid, steps_name, create_meta
5757
print(res_post)
5858
#end if
5959
#end if
60+
61+
return run_json_updated
6062
#end def

0 commit comments

Comments
 (0)