def delete_individuals(project, individual_guids, user): """Delete one or more individuals Args: project (object): Django ORM model for project individual_guids (list): GUIDs of individuals to delete Returns: list: Family objects for families with deleted individuals """ individuals_to_delete = Individual.objects.filter( family__project=project, guid__in=individual_guids) Sample.bulk_delete(user, individual__family__project=project, individual__guid__in=individual_guids) IgvSample.bulk_delete(user, individual__family__project=project, individual__guid__in=individual_guids) families = {individual.family for individual in individuals_to_delete} Individual.bulk_delete(user, queryset=individuals_to_delete) update_pedigree_images(families, user) families_with_deleted_individuals = list(families) return families_with_deleted_individuals
def handle(self, *args, **options): samples = (IgvSample.objects.filter( individual__family__project__name__in=args ) if args else IgvSample.objects.all()).filter( file_path__startswith='gs://' ).prefetch_related('individual', 'individual__family__project') missing_counter = collections.defaultdict(int) guids_of_samples_with_missing_file = set() for sample in tqdm.tqdm(samples, unit=" samples"): if not hl.hadoop_is_file(sample.file_path): individual_id = sample.individual.individual_id project = sample.individual.family.project.name missing_counter[project] += 1 logger.info('Individual: {} file not found: {}'.format(individual_id, sample.file_path)) if not options.get('dry_run'): guids_of_samples_with_missing_file.add(sample.guid) if len(guids_of_samples_with_missing_file) > 0: IgvSample.bulk_update(user=None, update_json={'file_path': ''}, guid__in=guids_of_samples_with_missing_file) logger.info('---- DONE ----') logger.info('Checked {} samples'.format(len(samples))) if missing_counter: logger.info('{} files not found:'.format(sum(missing_counter.values()))) for project_name, c in sorted(missing_counter.items(), key=lambda t: -t[1]): logger.info(' {} in {}'.format(c, project_name))
def _delete_project(project_guid, user): """Delete project. Args: project_guid (string): GUID of the project to delete user (object): Django ORM model for the user """ project = Project.objects.get(guid=project_guid) check_user_created_object_permissions(project, user) IgvSample.bulk_delete(user, individual__family__project=project) Sample.bulk_delete(user, individual__family__project=project) Individual.bulk_delete(user, family__project=project) Family.bulk_delete(user, project=project) project.delete_model(user, user_can_delete=True)
def handle(self, *args, **options): samples = (IgvSample.objects.filter( individual__family__project__name__in=args ) if args else IgvSample.objects.all()).filter( file_path__startswith='gs://' ).prefetch_related('individual', 'individual__family__project') missing_counter = collections.defaultdict(int) guids_of_samples_with_missing_file = set() project_name_to_missing_paths = collections.defaultdict(list) for sample in tqdm.tqdm(samples, unit=" samples"): if not hl.hadoop_is_file(sample.file_path): individual_id = sample.individual.individual_id project_name = sample.individual.family.project.name missing_counter[project_name] += 1 project_name_to_missing_paths[project_name].append((individual_id, sample.file_path)) logger.info('Individual: {} file not found: {}'.format(individual_id, sample.file_path)) if not options.get('dry_run'): guids_of_samples_with_missing_file.add(sample.guid) if len(guids_of_samples_with_missing_file) > 0: IgvSample.bulk_update(user=None, update_json={'file_path': ''}, guid__in=guids_of_samples_with_missing_file) logger.info('---- DONE ----') logger.info('Checked {} samples'.format(len(samples))) if missing_counter: logger.info('{} files not found:'.format(sum(missing_counter.values()))) for project_name, c in sorted(missing_counter.items(), key=lambda t: -t[1]): logger.info(' {} in {}'.format(c, project_name)) # post to slack if not options.get('dry_run'): slack_message = 'Found {} broken bam/cram path(s)\n'.format(sum(missing_counter.values())) for project_name, missing_paths_list in project_name_to_missing_paths.items(): slack_message += "\nIn project {}:\n".format(project_name) slack_message += "\n".join([ " {} {}".format(individual_id, path) for individual_id, path in missing_paths_list ]) communication_utils.safe_post_to_slack(SEQR_SLACK_DATA_ALERTS_NOTIFICATION_CHANNEL, slack_message)