def genomic_features(store, case_obj, sample_name, genes_only):
    """Extract and parse matchmaker-like genomic features from pinned variants
        of a patient
    Args:
        store(MongoAdapter) : connection to the database
        case_obj(dict): a scout case object
        sample_name(str): sample display name
        genes_only(bool): if True only gene names will be included in genomic features

    Returns:
        g_features(list): a list of genomic feature objects that looks like this:
            [
              {
                "gene": {
                  "id": "LIMS2"
                },
                "variant": {
                  "alternateBases": "C",
                  "assembly": "GRCh37",
                  "end": 128412081,
                  "referenceBases": "G",
                  "referenceName": "2",
                  "start": 128412080
                },
                "zygosity": 1
              },
              ....
            ]

    """
    g_features = []
    # genome build is required
    build = case_obj['genome_build']
    if not build in ['37', '38']:
        build = 'GRCh37'
    else:
        build = 'GRCh'+build

    individual_pinned_snvs = list(store.sample_variants( variants=case_obj.get('suspects'),
        sample_name=sample_name))

    # if genes_only is True don't add duplicated genes
    gene_set = set()
    for var in individual_pinned_snvs:
        # a variant could hit one or several genes so create a genomic feature for each of these genes
        hgnc_genes = var.get('hgnc_ids')
        # Looks like MatchMaker Exchange API accepts only variants that hit genes :(
        if not hgnc_genes:
            continue
        for hgnc_id in hgnc_genes:
            gene_obj = store.hgnc_gene(hgnc_id)
            if not gene_obj:
                continue
            g_feature = {
                'gene': {'id': gene_obj.get('hgnc_symbol')}
            }
            if genes_only and not hgnc_id in gene_set: # if only gene names should be shared
                gene_set.add(hgnc_id)
                g_features.append(g_feature)
                continue

            # if also variants should be shared:
            g_feature['variant'] = {
                'referenceName' : var['chromosome'],
                'start' : var['position'],
                'end' : var['end'],
                'assembly' : build,
                'referenceBases' :var['reference'],
                'alternateBases' : var['alternative'],
                'shareVariantLevelData' : True
            }
            zygosity = None
            # collect zygosity for the given sample
            zygosities = var['samples'] # it's a list with zygosity situation for each sample of the case
            for zyg in zygosities:
                if zyg.get('display_name') == sample_name: # sample of interest
                    zygosity = zyg['genotype_call'].count('1') + zyg['genotype_call'].count('2')
            g_feature['zygosity'] = zygosity
            g_features.append(g_feature)

    return g_features
def genomic_features(store, case_obj, sample_name, genes_only):
    """Extract and parse matchmaker-like genomic features from pinned variants
        of a patient
    Args:
        store(MongoAdapter) : connection to the database
        case_obj(dict): a scout case object
        sample_name(str): sample display name
        genes_only(bool): if True only gene names will be included in genomic features

    Returns:
        g_features(list): a list of genomic feature objects that looks like this:
            [
              {
                "gene": {
                  "id": "LIMS2"
                },
                "variant": {
                  "alternateBases": "C",
                  "assembly": "GRCh37",
                  "end": 128412081,
                  "referenceBases": "G",
                  "referenceName": "2",
                  "start": 128412080
                },
                "zygosity": 1
              },
              ....
            ]

    """
    g_features = []
    # genome build is required
    build = case_obj['genome_build']
    if not build in ['37', '38']:
        build = 'GRCh37'
    else:
        build = 'GRCh'+build

    individual_pinned_snvs = list(store.sample_variants( variants=case_obj.get('suspects'),
        sample_name=sample_name))

    # if genes_only is True don't add duplicated genes
    gene_set = set()
    for var in individual_pinned_snvs:
        # a variant could hit one or several genes so create a genomic feature for each of these genes
        hgnc_genes = var.get('hgnc_ids')
        # Looks like MatchMaker Exchange API accepts only variants that hit genes :(
        if not hgnc_genes:
            continue
        for hgnc_id in hgnc_genes:
            gene_obj = store.hgnc_gene(hgnc_id)
            if not gene_obj:
                continue
            g_feature = {
                'gene': {'id': gene_obj.get('hgnc_symbol')}
            }
            if genes_only and not hgnc_id in gene_set: # if only gene names should be shared
                gene_set.add(hgnc_id)
                g_features.append(g_feature)
                continue

            # if also variants should be shared:
            g_feature['variant'] = {
                'referenceName' : var['chromosome'],
                'start' : var['position'],
                'end' : var['end'],
                'assembly' : build,
                'referenceBases' :var['reference'],
                'alternateBases' : var['alternative'],
                'shareVariantLevelData' : True
            }
            zygosity = None
            # collect zygosity for the given sample
            zygosities = var['samples'] # it's a list with zygosity situation for each sample of the case
            for zyg in zygosities:
                if zyg.get('display_name') == sample_name: # sample of interest
                    zygosity = zyg['genotype_call'].count('1') + zyg['genotype_call'].count('2')
            g_feature['zygosity'] = zygosity
            g_features.append(g_feature)

    return g_features
def genomic_features ( store , case_obj , sample_name , genes_only ) : g_features = [ ] # genome build is required build = case_obj [ 'genome_build' ] if not build in [ '37' , '38' ] : build = 'GRCh37' else : build = 'GRCh' + build individual_pinned_snvs = list ( store . sample_variants ( variants = case_obj . get ( 'suspects' ) , sample_name = sample_name ) ) # if genes_only is True don't add duplicated genes gene_set = set ( ) for var in individual_pinned_snvs : # a variant could hit one or several genes so create a genomic feature for each of these genes hgnc_genes = var . get ( 'hgnc_ids' ) # Looks like MatchMaker Exchange API accepts only variants that hit genes :( if not hgnc_genes : continue for hgnc_id in hgnc_genes : gene_obj = store . hgnc_gene ( hgnc_id ) if not gene_obj : continue g_feature = { 'gene' : { 'id' : gene_obj . get ( 'hgnc_symbol' ) } } if genes_only and not hgnc_id in gene_set : # if only gene names should be shared gene_set . add ( hgnc_id ) g_features . append ( g_feature ) continue # if also variants should be shared: g_feature [ 'variant' ] = { 'referenceName' : var [ 'chromosome' ] , 'start' : var [ 'position' ] , 'end' : var [ 'end' ] , 'assembly' : build , 'referenceBases' : var [ 'reference' ] , 'alternateBases' : var [ 'alternative' ] , 'shareVariantLevelData' : True } zygosity = None # collect zygosity for the given sample zygosities = var [ 'samples' ] # it's a list with zygosity situation for each sample of the case for zyg in zygosities : if zyg . get ( 'display_name' ) == sample_name : # sample of interest zygosity = zyg [ 'genotype_call' ] . count ( '1' ) + zyg [ 'genotype_call' ] . count ( '2' ) g_feature [ 'zygosity' ] = zygosity g_features . append ( g_feature ) return g_features
Extract and parse matchmaker-like genomic features from pinned variants
        of a patient
    Args:
        store(MongoAdapter) : connection to the database
        case_obj(dict): a scout case object
        sample_name(str): sample display name
        genes_only(bool): if True only gene names will be included in genomic features

    Returns:
        g_features(list): a list of genomic feature objects that looks like this:
            [
              {
                "gene": {
                  "id": "LIMS2"
                },
                "variant": {
                  "alternateBases": "C",
                  "assembly": "GRCh37",
                  "end": 128412081,
                  "referenceBases": "G",
                  "referenceName": "2",
                  "start": 128412080
                },
                "zygosity": 1
              },
              ....
            ]
Extract and parse matchmaker - like genomic features from pinned variants of a patient Args : store ( MongoAdapter ) : connection to the database case_obj ( dict ) : a scout case object sample_name ( str ) : sample display name genes_only ( bool ) : if True only gene names will be included in genomic features