def save_individual_from_json_dict(project, indiv_dict): individual = Individual.objects.get_or_create( indiv_id=indiv_dict['indiv_id'], project=project)[0] individual.gender = indiv_dict.get('gender') individual.affected = indiv_dict.get('affected') individual.nickname = indiv_dict.get('nickname', '') individual.paternal_id = indiv_dict.get('paternal_id', '') individual.maternal_id = indiv_dict.get('maternal_id', '') individual.save() try: seqr_individual = get_seqr_individual_from_base_individual(individual) seqr_individual.sex = individual.gender seqr_individual.affected = individual.affected seqr_individual.display_name = individual.nickname seqr_individual.paternal_id = individual.paternal_id seqr_individual.maternal_id = individual.maternal_id seqr_individual.save() except Exception as e: print("Exception when updating SeqrIndividual: " + str(e)) sample_management.set_family_id_for_individual( individual, indiv_dict.get('family_id', '')) sample_management.set_individual_phenotypes_from_dict( individual, indiv_dict.get('phenotypes', {}))
def save_individual_from_json_dict(project, indiv_dict): individual = Individual.objects.get_or_create(indiv_id=indiv_dict['indiv_id'], project=project)[0] individual.gender = indiv_dict.get('gender') individual.affected = indiv_dict.get('affected') individual.nickname = indiv_dict.get('nickname', '') individual.paternal_id = indiv_dict.get('paternal_id', '') individual.maternal_id = indiv_dict.get('maternal_id', '') individual.save() sample_management.set_family_id_for_individual(individual, indiv_dict.get('family_id', '')) sample_management.set_individual_phenotypes_from_dict(individual, indiv_dict.get('phenotypes', {}))
def save_individual_from_json_dict(project, indiv_dict): individual = Individual.objects.get_or_create(indiv_id=indiv_dict["indiv_id"], project=project)[0] individual.gender = indiv_dict.get("gender") individual.affected = indiv_dict.get("affected") individual.nickname = indiv_dict.get("nickname", "") individual.paternal_id = indiv_dict.get("paternal_id", "") individual.maternal_id = indiv_dict.get("maternal_id", "") individual.save() sample_management.set_family_id_for_individual(individual, indiv_dict.get("family_id", "")) sample_management.set_individual_phenotypes_from_dict(individual, indiv_dict.get("phenotypes", {}))
def save_individual_from_json_dict(project, indiv_dict): individual = get_or_create_xbrowse_model(Individual, indiv_id=indiv_dict['indiv_id'], project=project)[0] update_xbrowse_model( individual, gender = indiv_dict.get('gender'), affected = indiv_dict.get('affected'), nickname = indiv_dict.get('nickname', ''), paternal_id = indiv_dict.get('paternal_id', ''), maternal_id = indiv_dict.get('maternal_id', '')) sample_management.set_family_id_for_individual(individual, indiv_dict.get('family_id', '')) sample_management.set_individual_phenotypes_from_dict(individual, indiv_dict.get('phenotypes', {}))
def handle(self, *args, **options): project = Project.objects.get(project_id=args[0]) d = json.load(open(args[1])) # create families for family_d in d['families']: family = Family.objects.get_or_create( project=project, family_id=family_d['family_id'])[0] family.family_name = family_d['family_name'] family.analysis_status = family_d['analysis_status'] family.save() # individuals for indiv_d in d['individuals']: individual = Individual.objects.get_or_create( project=project, indiv_id=indiv_d['indiv_id'])[0] individual.nickname = indiv_d['nickname'] individual.gender = indiv_d['gender'] individual.affected = indiv_d['affected'] individual.maternal_id = indiv_d['maternal_id'] individual.paternal_id = indiv_d['paternal_id'] individual.other_notes = indiv_d['other_notes'] individual.save() sample_management.set_family_id_for_individual( individual, indiv_d['family_id']) # phenotypes for pheno_d in d['project_phenotypes']: pheno = ProjectPhenotype.objects.get_or_create( slug=pheno_d['slug'], project=project)[0] pheno.name = pheno_d['name'] pheno.category = pheno_d['category'] pheno.datatype = pheno_d['datatype'] pheno.save() for ipheno_d in d['indiv_phenotypes']: indiv = Individual.objects.get(project=project, indiv_id=ipheno_d['indiv_id']) phenotype = ProjectPhenotype.objects.get(project=project, slug=ipheno_d['slug']) ipheno = IndividualPhenotype.objects.get_or_create( phenotype=phenotype, individual=indiv)[0] ipheno.boolean_val = None ipheno.float_val = None if phenotype.datatype == 'bool': ipheno.boolean_val = ipheno_d['val'] ipheno.save()
def handle(self, *args, **options): project = Project.objects.get(project_id=args[0]) d = json.load(open(args[1])) # create families for family_d in d['families']: family = Family.objects.get_or_create(project=project, family_id=family_d['family_id'])[0] family.family_name = family_d['family_name'] family.analysis_status = family_d['analysis_status'] family.save() # individuals for indiv_d in d['individuals']: individual = Individual.objects.get_or_create(project=project, indiv_id=indiv_d['indiv_id'])[0] individual.nickname = indiv_d['nickname'] individual.gender = indiv_d['gender'] individual.affected = indiv_d['affected'] individual.maternal_id = indiv_d['maternal_id'] individual.paternal_id = indiv_d['paternal_id'] individual.other_notes = indiv_d['other_notes'] individual.save() sample_management.set_family_id_for_individual(individual, indiv_d['family_id']) # phenotypes for pheno_d in d['project_phenotypes']: pheno = ProjectPhenotype.objects.get_or_create(slug=pheno_d['slug'], project=project)[0] pheno.name = pheno_d['name'] pheno.category = pheno_d['category'] pheno.datatype = pheno_d['datatype'] pheno.save() for ipheno_d in d['indiv_phenotypes']: indiv = Individual.objects.get(project=project, indiv_id=ipheno_d['indiv_id']) phenotype = ProjectPhenotype.objects.get(project=project, slug=ipheno_d['slug']) ipheno = IndividualPhenotype.objects.get_or_create(phenotype=phenotype, individual=indiv)[0] ipheno.boolean_val = None ipheno.float_val = None if phenotype.datatype == 'bool': ipheno.boolean_val = ipheno_d['val'] ipheno.save()
def copy_project(from_project, to_project, samples=False, settings=False, upsert=False, users=False, saved_variants=False, data=False): """ This is idempotent :param from_project: :param to_project: :param settings: :param upsert: :param users: :param saved_variants: :param data: :return: """ # todo: put all the data copying (vcf, bam, coverage) in one section # # project settings # if settings: # gene lists for d in from_project.get_gene_lists(): ProjectGeneList.objects.create(gene_list=d, project=to_project) # reference populations for r in from_project.get_private_reference_populations(): to_project.private_reference_populations.add(r) # phenotypes for from_p in from_project.get_phenotypes(): to_p = ProjectPhenotype.objects.get_or_create( project=to_project, slug=from_p.slug, category=from_p.category, datatype=from_p.datatype, name=from_p.name, )[0] # collaborators if users: managers = from_project.get_managers() for m in managers: to_project.set_as_manager(m) collaborators = from_project.get_collaborators() for u in collaborators: to_project.set_as_collaborator(u) # # sample data # if samples: # individuals with phenotypes for from_individual in from_project.individual_set.all(): if upsert: to_individual = Individual.objects.get_or_create( indiv_id=from_individual.indiv_id, project=to_project)[0] else: try: to_individual = Individual.objects.get( indiv_id=from_individual.indiv_id, project=to_project) except ObjectDoesNotExist: continue to_individual.nickname = from_individual.nickname to_individual.gender = from_individual.gender to_individual.affected = from_individual.affected to_individual.paternal_id = from_individual.paternal_id to_individual.maternal_id = from_individual.maternal_id to_individual.other_notes = from_individual.other_notes if data: to_individual.coverage_file = from_individual.coverage_file to_individual.save() if data: for vcf in from_individual.vcf_files.all(): to_individual.vcf_files.add(vcf) # individual phenotypes for from_phenotype in from_individual.get_phenotypes(): # project phenotype should already exist project_phenotype = ProjectPhenotype.objects.get( project=to_project, slug=from_phenotype.phenotype.slug, category=from_phenotype.phenotype.category, datatype=from_phenotype.phenotype.datatype) individual_phenotype = IndividualPhenotype.objects.get_or_create( phenotype=project_phenotype, individual=to_individual)[0] individual_phenotype.boolean_val = from_phenotype.boolean_val individual_phenotype.float_val = from_phenotype.float_val individual_phenotype.save() if from_individual.family: sample_management.set_family_id_for_individual( to_individual, from_individual.family.family_id) # families for from_family in from_project.family_set.all(): try: to_family = Family.objects.get(project=to_project, family_id=from_family.family_id) except ObjectDoesNotExist: continue to_family.family_name = from_family.family_name to_family.short_description = from_family.short_description to_family.about_family_content = from_family.about_family_content to_family.analysis_status = from_family.analysis_status to_family.save() def can_copy_cohort_into_project(cohort, to_project): for individual in cohort.individuals.all(): if not Individual.objects.filter( project=to_project, indiv_id=individual.indiv_id).exists(): return False return True # cohorts for from_cohort in from_project.cohort_set.all(): if not can_copy_cohort_into_project(from_cohort, to_project): print "Warning: could not load cohort %s" % from_cohort.cohort_id continue to_cohort = Cohort.objects.get_or_create( project=to_project, cohort_id=from_cohort.cohort_id)[0] to_cohort.display_name = from_cohort.display_name to_cohort.short_description = from_cohort.short_description to_cohort.save() for from_i in from_cohort.individuals.all(): to_i = Individual.objects.get(project=to_project, indiv_id=from_i.indiv_id) to_cohort.individuals.add(to_i) # flags if saved_variants: # variant notes for from_note in VariantNote.objects.filter(project=from_project): to_note = VariantNote.objects.get_or_create( user=from_note.user, date_saved=from_note.date_saved, project=to_project, note=from_note.note, xpos=from_note.xpos, ref=from_note.ref, alt=from_note.alt, )[0] if from_note.family: to_note.family = Family.objects.get( project=to_project, family_id=from_note.family.family_id) if from_note.individual: to_note.individual = Individual.objects.get( project=to_project, indiv_id=from_note.individual.indiv_id) # variant tags # start with project tags # should these be in the --settings or --saved_variants parameters? for from_tag in ProjectTag.objects.filter(project=from_project): to_tag = ProjectTag.objects.get_or_create( project=to_project, tag=from_tag.tag, title=from_tag.title, color=from_tag.color, )[0] # now variant tags for from_tag in VariantTag.objects.filter( project_tag__project=from_project): to_project_tag = ProjectTag.objects.get( project=to_project, tag=from_tag.project_tag.tag) to_family = None if from_tag.family: to_family = Family.objects.get( project=to_project, family_id=from_tag.family.family_id) to_tag = VariantTag.objects.get_or_create( project_tag=to_project_tag, family=to_family, xpos=from_tag.xpos, ref=from_tag.ref, alt=from_tag.alt, )[0]
def copy_project(from_project, to_project, samples=False, settings=False, upsert=False, users=False, saved_variants=False, data=False): """ This is idempotent :param from_project: :param to_project: :param settings: :param upsert: :param users: :param saved_variants: :param data: :return: """ # todo: put all the data copying (vcf, bam, coverage) in one section # # project settings # if settings: # gene lists for d in from_project.get_gene_lists(): ProjectGeneList.objects.create(gene_list=d, project=to_project) # reference populations for r in from_project.get_private_reference_populations(): to_project.private_reference_populations.add(r) # phenotypes for from_p in from_project.get_phenotypes(): to_p = ProjectPhenotype.objects.get_or_create( project=to_project, slug=from_p.slug, category=from_p.category, datatype=from_p.datatype, name=from_p.name, )[0] # collaborators if users: managers = from_project.get_managers() for m in managers: to_project.set_as_manager(m) collaborators = from_project.get_collaborators() for u in collaborators: to_project.set_as_collaborator(u) # # sample data # if samples: # individuals with phenotypes for from_individual in from_project.individual_set.all(): if upsert: to_individual = Individual.objects.get_or_create(indiv_id=from_individual.indiv_id, project=to_project)[0] else: try: to_individual = Individual.objects.get(indiv_id=from_individual.indiv_id, project=to_project) except ObjectDoesNotExist: continue to_individual.nickname = from_individual.nickname to_individual.gender = from_individual.gender to_individual.affected = from_individual.affected to_individual.paternal_id = from_individual.paternal_id to_individual.maternal_id = from_individual.maternal_id to_individual.other_notes = from_individual.other_notes if data: to_individual.coverage_file = from_individual.coverage_file to_individual.save() if data: for vcf in from_individual.vcf_files.all(): to_individual.vcf_files.add(vcf) # individual phenotypes for from_phenotype in from_individual.get_phenotypes(): # project phenotype should already exist project_phenotype = ProjectPhenotype.objects.get(project=to_project, slug=from_phenotype.phenotype.slug, category=from_phenotype.phenotype.category, datatype=from_phenotype.phenotype.datatype ) individual_phenotype = IndividualPhenotype.objects.get_or_create( phenotype=project_phenotype, individual=to_individual )[0] individual_phenotype.boolean_val = from_phenotype.boolean_val individual_phenotype.float_val = from_phenotype.float_val individual_phenotype.save() if from_individual.family: sample_management.set_family_id_for_individual(to_individual, from_individual.family.family_id) # families for from_family in from_project.family_set.all(): try: to_family = Family.objects.get(project=to_project, family_id=from_family.family_id) except ObjectDoesNotExist: continue to_family.family_name = from_family.family_name to_family.short_description = from_family.short_description to_family.about_family_content = from_family.about_family_content to_family.analysis_status = from_family.analysis_status to_family.save() def can_copy_cohort_into_project(cohort, to_project): for individual in cohort.individuals.all(): if not Individual.objects.filter(project=to_project, indiv_id=individual.indiv_id).exists(): return False return True # cohorts for from_cohort in from_project.cohort_set.all(): if not can_copy_cohort_into_project(from_cohort, to_project): print "Warning: could not load cohort %s" % from_cohort.cohort_id continue to_cohort = Cohort.objects.get_or_create(project=to_project, cohort_id=from_cohort.cohort_id)[0] to_cohort.display_name = from_cohort.display_name to_cohort.short_description = from_cohort.short_description to_cohort.save() for from_i in from_cohort.individuals.all(): to_i = Individual.objects.get(project=to_project, indiv_id=from_i.indiv_id) to_cohort.individuals.add(to_i) # flags if saved_variants: # variant notes for from_note in VariantNote.objects.filter(project=from_project): to_note = VariantNote.objects.get_or_create( user=from_note.user, date_saved=from_note.date_saved, project=to_project, note=from_note.note, xpos=from_note.xpos, ref=from_note.ref, alt=from_note.alt, )[0] if from_note.family: to_note.family = Family.objects.get(project=to_project, family_id=from_note.family.family_id) if from_note.individual: to_note.individual = Individual.objects.get(project=to_project, indiv_id=from_note.individual.indiv_id) # variant tags # start with project tags # should these be in the --settings or --saved_variants parameters? for from_tag in ProjectTag.objects.filter(project=from_project): to_tag = ProjectTag.objects.get_or_create( project=to_project, tag=from_tag.tag, title=from_tag.title, color=from_tag.color, )[0] # now variant tags for from_tag in VariantTag.objects.filter(project_tag__project=from_project): to_project_tag = ProjectTag.objects.get(project=to_project, tag=from_tag.project_tag.tag) to_family = None if from_tag.family: to_family = Family.objects.get(project=to_project, family_id=from_tag.family.family_id) to_tag = VariantTag.objects.get_or_create( project_tag=to_project_tag, family=to_family, xpos=from_tag.xpos, ref=from_tag.ref, alt=from_tag.alt, )[0]