scout/parse/clinvar.py
def get_objects_from_form(variant_ids, form_fields, object_type):
    """Extract the objects to be saved in the clinvar database collection.
       object_type param specifies if these objects are variant or casedata objects

       Args:
        variant_ids(list): list of database variant ids
        form_fields(dict): it's the submission form dictionary. Keys have the same names as CLINVAR_HEADER and CASEDATA_HEADER
        object_type(str): either 'variant' or 'case_data'

       Returns:
        submission_objects(list): list of submission objects of either type 'variant' or 'casedata'
    """
    submission_fields = []
    if object_type == 'variant':
        submission_fields = CLINVAR_HEADER
    else: #collect casedata objects
        submission_fields = CASEDATA_HEADER

    # A list of objects (variants of casedata info) to be saved into clinvar database collection
    submission_objects = []

    # Loop over the form fields and collect the data:
    for variant_id in variant_ids: # loop over the variants

        subm_obj = {} # A new submission object for each

        # Don't included casedata for a variant unless specified by user
        if object_type == 'casedata' and 'casedata_'+variant_id not in form_fields:
            continue

        subm_obj['csv_type'] = object_type
        subm_obj['case_id'] = form_fields.get('case_id')
        subm_obj['category'] = form_fields.get('category@'+variant_id)

        for key, values in submission_fields.items(): # loop over the form info fields
            field_value = form_fields.get(key+'@'+variant_id)
            if field_value and not field_value == '-':
                if key == 'ref_seq': # split this field into
                    refseq_raw = field_value.split('|')
                    subm_obj['ref_seq'] = refseq_raw[0]
                    subm_obj['hgvs'] = refseq_raw[1]
                else:
                    subm_obj[key] = field_value

        # Create a unique ID for the database
        # For casedata : = caseID_sampleID_variantID
        # For variants : ID = caseID_variantID
        if object_type == 'casedata':
            subm_obj['_id'] = str(subm_obj['case_id']) + '_' + variant_id + '_' + str(subm_obj['individual_id'])
        else:
            subm_obj['_id'] = str(subm_obj['case_id']) + '_' + variant_id

        submission_objects.append(subm_obj)

    return submission_objects
def get_objects_from_form(variant_ids, form_fields, object_type):
    """Extract the objects to be saved in the clinvar database collection.
       object_type param specifies if these objects are variant or casedata objects

       Args:
        variant_ids(list): list of database variant ids
        form_fields(dict): it's the submission form dictionary. Keys have the same names as CLINVAR_HEADER and CASEDATA_HEADER
        object_type(str): either 'variant' or 'case_data'

       Returns:
        submission_objects(list): list of submission objects of either type 'variant' or 'casedata'
    """
    submission_fields = []
    if object_type == 'variant':
        submission_fields = CLINVAR_HEADER
    else: #collect casedata objects
        submission_fields = CASEDATA_HEADER

    # A list of objects (variants of casedata info) to be saved into clinvar database collection
    submission_objects = []

    # Loop over the form fields and collect the data:
    for variant_id in variant_ids: # loop over the variants

        subm_obj = {} # A new submission object for each

        # Don't included casedata for a variant unless specified by user
        if object_type == 'casedata' and 'casedata_'+variant_id not in form_fields:
            continue

        subm_obj['csv_type'] = object_type
        subm_obj['case_id'] = form_fields.get('case_id')
        subm_obj['category'] = form_fields.get('category@'+variant_id)

        for key, values in submission_fields.items(): # loop over the form info fields
            field_value = form_fields.get(key+'@'+variant_id)
            if field_value and not field_value == '-':
                if key == 'ref_seq': # split this field into
                    refseq_raw = field_value.split('|')
                    subm_obj['ref_seq'] = refseq_raw[0]
                    subm_obj['hgvs'] = refseq_raw[1]
                else:
                    subm_obj[key] = field_value

        # Create a unique ID for the database
        # For casedata : = caseID_sampleID_variantID
        # For variants : ID = caseID_variantID
        if object_type == 'casedata':
            subm_obj['_id'] = str(subm_obj['case_id']) + '_' + variant_id + '_' + str(subm_obj['individual_id'])
        else:
            subm_obj['_id'] = str(subm_obj['case_id']) + '_' + variant_id

        submission_objects.append(subm_obj)

    return submission_objects
Extract the objects to be saved in the clinvar database collection.
       object_type param specifies if these objects are variant or casedata objects

       Args:
        variant_ids(list): list of database variant ids
        form_fields(dict): it's the submission form dictionary. Keys have the same names as CLINVAR_HEADER and CASEDATA_HEADER
        object_type(str): either 'variant' or 'case_data'

       Returns:
        submission_objects(list): list of submission objects of either type 'variant' or 'casedata'