Beispiel #1
0
def update_individual_hpo_terms(request, individual_guid):
    """Updates features fields for the given Individual
    """

    individual = Individual.objects.get(guid=individual_guid)

    project = individual.family.project

    check_project_permissions(project, request.user, can_edit=True)

    request_json = json.loads(request.body)

    for feature_key in [
            'features', 'absentFeatures', 'nonstandardFeatures',
            'absentNonstandardFeatures'
    ]:
        orm_key = _to_snake_case(feature_key)
        value = [get_parsed_feature(feature) for feature in request_json[feature_key]] \
            if request_json.get(feature_key) else None
        setattr(individual, orm_key, value)
    individual.save()

    return create_json_response({
        individual.guid:
        _get_json_for_individual(individual,
                                 request.user,
                                 add_hpo_details=True)
    })
Beispiel #2
0
def update_individual_hpo_terms(request, individual_guid):
    """Updates features fields for the given Individual
    """

    individual = Individual.objects.get(guid=individual_guid)

    project = individual.family.project

    check_project_permissions(project, request.user, can_edit=True)

    request_json = json.loads(request.body)

    update_json = {
        key:
        [get_parsed_feature(feature)
         for feature in request_json[key]] if request_json.get(key) else None
        for key in [
            'features', 'absentFeatures', 'nonstandardFeatures',
            'absentNonstandardFeatures'
        ]
    }
    update_model_from_json(individual, update_json, user=request.user)

    return create_json_response({
        individual.guid:
        _get_json_for_individual(individual,
                                 request.user,
                                 add_hpo_details=True)
    })
Beispiel #3
0
def _update_individual_phenotips_fields(indiv, phenotips_json):
    if phenotips_json.get('date_of_birth'):
        indiv.birth_year = datetime.strptime(phenotips_json['date_of_birth'],
                                             '%Y-%m-%d').year
    if phenotips_json.get('life_status') == 'deceased':
        indiv.death_year = datetime.strptime(phenotips_json['date_of_death'], '%Y-%m-%d').year \
            if phenotips_json.get('date_of_death') else 0

    if phenotips_json.get('global_age_of_onset'):
        onset_label = phenotips_json['global_age_of_onset'][0]['label']
        indiv.onset_age = seqr.models.Individual.ONSET_AGE_REVERSE_LOOKUP[
            onset_label]
    if phenotips_json.get('global_mode_of_inheritance'):
        indiv.expected_inheritance = [
            seqr.models.Individual.INHERITANCE_REVERSE_LOOKUP[i['label']]
            for i in phenotips_json['global_mode_of_inheritance']
        ]

    if phenotips_json['ethnicity']['maternal_ethnicity']:
        indiv.maternal_ethnicity = phenotips_json['ethnicity'][
            'maternal_ethnicity']
    if phenotips_json['ethnicity']['paternal_ethnicity']:
        indiv.paternal_ethnicity = phenotips_json['ethnicity'][
            'paternal_ethnicity']

    family_history = phenotips_json.get('family_history') or {}
    if family_history.get('consanguinity') is not None:
        indiv.consanguinity = family_history['consanguinity']
    if family_history.get('affectedRelatives') is not None:
        indiv.affected_relatives = family_history['affectedRelatives']

    present_features = []
    absent_features = []
    nonstandard_features = []
    absent_nonstandard_features = []
    for feature in phenotips_json.get('features') or []:
        feature_list = present_features if feature[
            'observed'] == 'yes' else absent_features
        feature_list.append(get_parsed_feature(feature))
    for feature in phenotips_json.get('nonstandard_features') or []:
        feature_list = nonstandard_features if feature[
            'observed'] == 'yes' else absent_nonstandard_features
        feature_list.append(
            get_parsed_feature(feature,
                               feature_id=feature['label'],
                               additional_fields=['categories']))
    if present_features:
        indiv.features = present_features
    if absent_features:
        indiv.absent_features = absent_features
    if nonstandard_features:
        indiv.nonstandard_features = nonstandard_features
    if absent_nonstandard_features:
        indiv.absent_nonstandard_features = absent_nonstandard_features

    if phenotips_json.get('disorders'):
        mim_ids = map(lambda d: int(d['id'].lstrip('MIM:')),
                      phenotips_json['disorders'])
        indiv.disorders = mim_ids

    if phenotips_json.get('genes'):
        indiv.candidate_genes = phenotips_json['genes']
    if phenotips_json.get('rejectedGenes'):
        indiv.rejected_genes = phenotips_json['rejectedGenes']

    prenatal = phenotips_json['prenatal_perinatal_history']
    for field in [
            'assistedReproduction_fertilityMeds',
            'assistedReproduction_iui',
            'ivf',
            'icsi',
            'assistedReproduction_surrogacy',
            'assistedReproduction_donoregg',
            'assistedReproduction_donorsperm',
    ]:
        if prenatal.get(field) is not None:
            indiv_field = 'ar_{}'.format(
                _to_snake_case(field.replace('assistedReproduction_', '')))
            setattr(indiv, indiv_field, prenatal[field])