Skip to content

Commit

Permalink
single loading error per project
Browse files Browse the repository at this point in the history
  • Loading branch information
hanars committed Dec 19, 2024
1 parent d0c5c19 commit 90f2145
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
25 changes: 13 additions & 12 deletions seqr/management/commands/check_for_new_samples_from_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,28 @@ def _load_new_samples(cls, metadata_path, genome_version, dataset_type, run_vers
failed_families_by_guid = {f['guid']: f for f in Family.objects.filter(
guid__in={family for families in failed_family_samples.values() for family in families}
).values('guid', 'family_id', 'project__name')}
failures_by_project_check = defaultdict(lambda: defaultdict(list))
for check, check_failures in failed_family_samples.items():
failures_by_project = defaultdict(list)
for family_guid, failure_data in check_failures.items():
family = failed_families_by_guid[family_guid]
failures_by_project[family['project__name']].append(
failures_by_project_check[family['project__name']][check].append(
f'- {family["family_id"]}: {"; ".join(failure_data["reasons"])}'
)
for project, failures in failures_by_project.items():
for project, failures_by_check in failures_by_project_check.items():
messages = [f'Encountered the following errors loading {project}:']
for check, failures in failures_by_check.items():
summary = '\n'.join(sorted(failures))
split_pdos = split_project_pdos.get(project)
if split_pdos:
summary += f'\n\nSkipped samples in this project have been moved to {", ".join(split_pdos)}'

messages.append(f"The following {len(failures)} families failed {check.replace('_', ' ')}:\n{summary}")
if check == RELATEDNESS_CHECK_NAME and relatedness_check_file_path:
downloadable_link = f'https://storage.cloud.google.com/{relatedness_check_file_path[5:]}'
summary += f'\n\nRelatedness check results: {downloadable_link}'
messages.append(f'Relatedness check results: {downloadable_link}')

safe_post_to_slack(
SEQR_SLACK_LOADING_NOTIFICATION_CHANNEL,
f'The following {len(failures)} families failed {check.replace("_", " ")} in {project}:\n{summary}'
)
split_pdos = split_project_pdos.get(project)
if split_pdos:
messages.append(f'Skipped samples in this project have been moved to {", ".join(split_pdos)}')
safe_post_to_slack(
SEQR_SLACK_LOADING_NOTIFICATION_CHANNEL, '\n\n'.join(messages),
)

# Reload saved variant JSON
updated_variants_by_id = update_projects_saved_variant_json(
Expand Down
30 changes: 15 additions & 15 deletions seqr/management/tests/check_for_new_samples_from_pipeline_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def test_command(self, mock_email, mock_airtable_utils):
])

# Test notifications
self.assertEqual(self.mock_send_slack.call_count, 9)
self.assertEqual(self.mock_send_slack.call_count, 7)
self.mock_send_slack.assert_has_calls([
mock.call(
'seqr-data-loading',
Expand All @@ -567,24 +567,24 @@ def test_command(self, mock_email, mock_airtable_utils):
),
mock.call(
'seqr_loading_notifications',
"""The following 1 families failed relatedness check in 1kg project nåme with uniçøde:
- 1: Sample NA19679 has expected relation "parent" to NA19675 but has coefficients [0.0, 0.8505002045292791, 0.14949979547072176, 0.5747498977353613]; Sample NA19678 has expected relation "sibling" to NA19675 but has coefficients [0.17424888135104177, 0.6041745754450025, 0.22157654320395614, 0.5236638309264574]\n\nRelatedness check results: https://storage.cloud.google.com/seqr-loading-temp/v3.1/GRCh38/SNV_INDEL/relatedness_check/test_callset_hash.tsv""",
),
mock.call(
'seqr_loading_notifications',
"""The following 1 families failed sex check in 1kg project nåme with uniçøde:
- 1: Sample NA19679 has pedigree sex F but imputed sex M""",
"""Encountered the following errors loading 1kg project nåme with uniçøde:
The following 1 families failed relatedness check:
- 1: Sample NA19679 has expected relation "parent" to NA19675 but has coefficients [0.0, 0.8505002045292791, 0.14949979547072176, 0.5747498977353613]; Sample NA19678 has expected relation "sibling" to NA19675 but has coefficients [0.17424888135104177, 0.6041745754450025, 0.22157654320395614, 0.5236638309264574]\n\nRelatedness check results: https://storage.cloud.google.com/seqr-loading-temp/v3.1/GRCh38/SNV_INDEL/relatedness_check/test_callset_hash.tsv
The following 1 families failed sex check:
- 1: Sample NA19679 has pedigree sex F but imputed sex M
The following 2 families failed missing samples:
- 2: Missing samples: {'HG00732', 'HG00733'}
- 3: Missing samples: {'NA20870'}""",
),
mock.call(
'seqr_loading_notifications',
"""The following 1 families failed sex check in Non-Analyst Project:
"""Encountered the following errors loading Non-Analyst Project:
The following 1 families failed sex check:
- 14: Sample NA21987 has pedigree sex M but imputed sex F""",
),
mock.call(
'seqr_loading_notifications',
"""The following 2 families failed missing samples in 1kg project nåme with uniçøde:
- 2: Missing samples: {'HG00732', 'HG00733'}
- 3: Missing samples: {'NA20870'}""",
),
mock.call(
'seqr-data-loading',
Expand Down

0 comments on commit 90f2145

Please sign in to comment.