Skip to content

Commit

Permalink
Merge pull request #4482 from broadinstitute/pdo-missing-project-error
Browse files Browse the repository at this point in the history
Pdo missing project error
  • Loading branch information
hanars authored Nov 18, 2024
2 parents 89bbff8 + b7fcf0c commit 0e59ad2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
15 changes: 11 additions & 4 deletions seqr/views/apis/data_manager_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,10 @@ def get_loaded_projects(request, sample_type, dataset_type):
projects = get_internal_projects().filter(is_demo=False)
project_samples = None
if AirtableSession.is_airtable_enabled():
project_samples = _fetch_airtable_loadable_project_samples(request.user, dataset_type, sample_type)
try:
project_samples = _fetch_airtable_loadable_project_samples(request.user, dataset_type, sample_type)
except ValueError as e:
return create_json_response({'error': str(e)}, status=400)
projects = projects.filter(guid__in=project_samples.keys())
if dataset_type == Sample.DATASET_TYPE_VARIANT_CALLS:
exclude_sample_type = Sample.SAMPLE_TYPE_WES if sample_type == Sample.SAMPLE_TYPE_WGS else Sample.SAMPLE_TYPE_WGS
Expand Down Expand Up @@ -587,9 +590,13 @@ def _get_valid_project_samples(project_samples, dataset_type, sample_type, user)

missing_family_samples = defaultdict(list)
for project, individuals_by_sample_id in missing_project_samples.items():
loaded_samples = {sample['sample_id'] for sample in _get_dataset_type_samples_for_matched_pdos(
user, dataset_type, sample_type, AVAILABLE_PDO_STATUSES, project_guid=project,
)}
try:
loaded_samples = {sample['sample_id'] for sample in _get_dataset_type_samples_for_matched_pdos(
user, dataset_type, sample_type, AVAILABLE_PDO_STATUSES, project_guid=project,
)}
except ValueError as e:
errors.append(str(e))
continue
for sample_id, individual in individuals_by_sample_id.items():
if sample_id in loaded_samples:
individual_ids.append(individual['id'])
Expand Down
15 changes: 8 additions & 7 deletions seqr/views/utils/airtable_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.core.exceptions import PermissionDenied

from seqr.utils.logging_utils import SeqrLogger
from seqr.utils.middleware import ErrorsWarningsException
from seqr.views.utils.terra_api_utils import is_cloud_authenticated

from settings import AIRTABLE_API_KEY, AIRTABLE_URL, BASE_URL
Expand Down Expand Up @@ -171,11 +170,15 @@ def get_samples_for_matched_pdos(self, pdo_statuses, pdo_fields=None, project_gu
invalid_pdo_samples = []
for sample in sample_records.values():
sample_id = sample.get('SeqrCollaboratorSampleID') or sample['CollaboratorSampleID']
project_guids = [
re.match(f'{BASE_URL}project/([^/]+)/project_page', url).group(1) for url in sample['SeqrProject']
project_matches = [
re.match(f'{BASE_URL}project/([^/]+)/project_page', url)
for url in sample.get('SeqrProject', []) if url
]
if len(project_guids) > 1 and len(project_guids) < len(sample['PDOStatus']):
if any(pm is None for pm in project_matches) or (1 < len(project_matches) < len(sample['PDOStatus'])):
invalid_pdo_samples.append(sample_id)
continue

project_guids = [match.group(1) for match in project_matches]
pdos = [{
'project_guid': project_guids[i] if len(project_guids) > 1 else project_guids[0],
**{field: sample[field][i] for field in pdo_fields}
Expand All @@ -189,8 +192,6 @@ def get_samples_for_matched_pdos(self, pdo_statuses, pdo_fields=None, project_gu

if invalid_pdo_samples:
samples = ', '.join(sorted(invalid_pdo_samples))
raise ErrorsWarningsException([
f'The following samples are associated with misconfigured PDOs in Airtable: {samples}'
])
raise ValueError(f'The following samples are associated with misconfigured PDOs in Airtable: {samples}')

return {record_id: sample for record_id, sample in sample_records.items() if sample['pdos']}

0 comments on commit 0e59ad2

Please sign in to comment.