Esempio n. 1
0
def family_coverage_gene_list(request, family, gene_list):
    """
    Table of summary coverages for each gene in the gene list
    """
    sample_id_list = [str(individual.pk) for individual in family.get_individuals()]

    cache_key = ('family_coverage_gene_list', family.project.project_id, family.family_id, gene_list.slug)
    cached_results = server_utils.get_cached_results(cache_key)
    if cached_results:
        gene_coverages = cached_results
    else:
        gene_coverages = []
        for gene_id in gene_list.gene_id_list():
            d = {
                'gene_id': gene_id,
                'gene_name': get_reference().get_gene_symbol(gene_id),
                'totals': get_coverage_store().get_coverage_totals_for_gene(gene_id, sample_id_list)
            }
            d['coding_size'] = sum(d['totals'].values())
            try:
                d['percent'] = float(d['totals']['callable'])*100 / d['coding_size']
            except ZeroDivisionError:
                d['percent'] = 0
            gene_coverages.append(d)
        server_utils.save_results_cache(cache_key, gene_coverages)

    return render(request, 'coverage/family_coverage_gene_list.html', {
        'project': family.project,
        'family': family,
        'gene_list': gene_list,
        'gene_coverages': gene_coverages,
    })
Esempio n. 2
0
def family_coverage_gene_list(request, family, gene_list):
    """
    Table of summary coverages for each gene in the gene list
    """
    sample_id_list = [str(individual.pk) for individual in family.get_individuals()]

    cache_key = ('family_coverage_gene_list', family.project.project_id, family.family_id, gene_list.slug)
    cached_results = server_utils.get_cached_results(cache_key)
    if cached_results:
        gene_coverages = cached_results
    else:
        gene_coverages = []
        for gene_id in gene_list.gene_id_list():
            d = {
                'gene_id': gene_id,
                'gene_name': get_reference().get_gene_symbol(gene_id),
                'totals': get_coverage_store().get_coverage_totals_for_gene(gene_id, sample_id_list)
            }
            d['coding_size'] = sum(d['totals'].values())
            try:
                d['percent'] = float(d['totals']['callable'])*100 / d['coding_size']
            except ZeroDivisionError:
                d['percent'] = 0
            gene_coverages.append(d)
        server_utils.save_results_cache(cache_key, gene_coverages)

    return render(request, 'coverage/family_coverage_gene_list.html', {
        'project': family.project,
        'family': family,
        'gene_list': gene_list,
        'gene_coverages': gene_coverages,
    })
Esempio n. 3
0
    def has_data(self, data_key):
        """
        Is data for data_key available and fully loaded for this family?
        """
        if data_key == 'variation':
            return self.has_variant_data() and self.get_data_status(
            ) == 'loaded'
        elif data_key == 'breakpoints':
            log.info("checking for breakpoints")
            return self.has_breakpoint_data()
        elif data_key == 'exome_coverage':
            if self.has_coverage_data() is False:
                return False
            sample_ids = [
                indiv.get_coverage_store_id()
                for indiv in self.get_individuals()
            ]
            statuses = set(
                get_coverage_store().get_sample_statuses(sample_ids).values())

            # must be at least one fully loaded
            if 'loaded' not in statuses:
                return False

            # "there are no statuses other than loaded and None"
            return len(statuses.union({'loaded', None})) == 2
Esempio n. 4
0
def family_coverage_gene(request, family, gene_id):

    project_id = family.project.project_id
    gene = get_reference().get_gene(gene_id)
    gene_structure = get_reference().get_gene_structure(gene_id)
    individuals = family.get_individuals()
    indiv_ids = [i.indiv_id for i in individuals]
    num_individuals = len(indiv_ids)

    coding_regions = []
    for c in get_coding_regions_from_gene_structure(gene_id, gene_structure):
        coding_region = {}
        coding_region['start'] = genomeloc.get_chr_pos(c.xstart)[1]
        coding_region['stop'] = genomeloc.get_chr_pos(c.xstop)[1]
        coding_region['gene_id'] = c.gene_id
        coding_region['size'] = c.xstop - c.xstart + 1
        coding_regions.append(coding_region)

    coverages = {}
    for individual in individuals:
        coverages[
            individual.indiv_id] = get_coverage_store().get_coverage_for_gene(
                str(individual.pk), gene['gene_id'])

    whole_gene = Counter({'callable': 0, 'low_coverage': 0, 'poor_mapping': 0})
    for coverage_spec in coverages.values():
        whole_gene['callable'] += coverage_spec['gene_totals']['callable']
        whole_gene['low_coverage'] += coverage_spec['gene_totals'][
            'low_coverage']
        whole_gene['poor_mapping'] += coverage_spec['gene_totals'][
            'poor_mapping']
    gene_coding_size = 0
    for c in coding_regions:
        gene_coding_size += c['stop'] - c['start'] + 1
    totalsize = gene_coding_size * num_individuals
    whole_gene['ratio_callable'] = whole_gene['callable'] / float(totalsize)
    whole_gene['ratio_low_coverage'] = whole_gene['low_coverage'] / float(
        totalsize)
    whole_gene['ratio_poor_mapping'] = whole_gene['poor_mapping'] / float(
        totalsize)
    whole_gene['gene_coding_size'] = gene_coding_size

    return render(
        request, 'coverage/family_coverage_gene.html', {
            'project': family.project,
            'family': family,
            'gene': gene,
            'coverages_json': json.dumps(coverages),
            'whole_gene_json': json.dumps(whole_gene),
            'coding_regions_json': json.dumps(coding_regions),
            'indiv_ids_json': json.dumps(indiv_ids),
            'individuals': individuals,
            'whole_gene': whole_gene,
        })
Esempio n. 5
0
def clean_project(project_id):
    """
    Clear data for this project from all the xbrowse resources:
     - datastore
     - coverage store
     - cnv store
    Does not remove any of the project's data links - so no data is lost, but everything must be rebuilt
    """
    project = Project.objects.get(project_id=project_id)
    individuals = project.get_individuals()

    # datastore
    get_mall(project_id).variant_store.delete_project(project_id)

    # coverage store
    for individual in individuals:
        get_coverage_store().remove_sample(individual.get_coverage_store_id())

    # cnv store
    for individual in individuals:
        get_cnv_store().remove_sample(individual.get_coverage_store_id())
Esempio n. 6
0
def clean_project(project_id):
    """
    Clear data for this project from all the xbrowse resources:
     - datastore
     - coverage store
     - cnv store
    Does not remove any of the project's data links - so no data is lost, but everything must be rebuilt
    """
    project = Project.objects.get(project_id=project_id)
    individuals = project.get_individuals()

    # datastore
    get_mall(project_id).variant_store.delete_project(project_id)

    # coverage store
    for individual in individuals:
        get_coverage_store().remove_sample(individual.get_coverage_store_id())

    # cnv store
    for individual in individuals:
        get_cnv_store().remove_sample(individual.get_coverage_store_id())
Esempio n. 7
0
def family_coverage_gene(request, family, gene_id):

    project_id = family.project.project_id
    gene = get_reference().get_gene(gene_id)
    gene_structure = get_reference().get_gene_structure(gene_id)
    individuals = family.get_individuals()
    indiv_ids = [i.indiv_id for i in individuals]
    num_individuals = len(indiv_ids)

    coding_regions = []
    for c in get_coding_regions_from_gene_structure(gene_id, gene_structure):
        coding_region = {}
        coding_region['start'] = genomeloc.get_chr_pos(c.xstart)[1]
        coding_region['stop'] = genomeloc.get_chr_pos(c.xstop)[1]
        coding_region['gene_id'] = c.gene_id
        coding_region['size'] = c.xstop-c.xstart+1
        coding_regions.append(coding_region)

    coverages = {}
    for individual in individuals:
        coverages[individual.indiv_id] = get_coverage_store().get_coverage_for_gene(
            str(individual.pk),
            gene['gene_id']
        )

    whole_gene = Counter({'callable': 0, 'low_coverage': 0, 'poor_mapping': 0})
    for coverage_spec in coverages.values():
        whole_gene['callable'] += coverage_spec['gene_totals']['callable']
        whole_gene['low_coverage'] += coverage_spec['gene_totals']['low_coverage']
        whole_gene['poor_mapping'] += coverage_spec['gene_totals']['poor_mapping']
    gene_coding_size = 0
    for c in coding_regions:
        gene_coding_size += c['stop']-c['start']+1
    totalsize = gene_coding_size*num_individuals
    whole_gene['ratio_callable'] = whole_gene['callable'] / float(totalsize)
    whole_gene['ratio_low_coverage'] = whole_gene['low_coverage'] / float(totalsize)
    whole_gene['ratio_poor_mapping'] = whole_gene['poor_mapping'] / float(totalsize)
    whole_gene['gene_coding_size'] = gene_coding_size

    return render(request, 'coverage/family_coverage_gene.html', {
        'project': family.project,
        'family': family,
        'gene': gene,
        'coverages_json': json.dumps(coverages),
        'whole_gene_json': json.dumps(whole_gene),
        'coding_regions_json': json.dumps(coding_regions),
        'indiv_ids_json': json.dumps(indiv_ids),
        'individuals': individuals,
        'whole_gene': whole_gene,
    })
Esempio n. 8
0
    def has_data(self, data_key):
        """
        Is data for data_key available and fully loaded for this family?
        """
        if data_key == 'variation':
            return self.has_variant_data() and self.get_data_status() == 'loaded'
        elif data_key == 'exome_coverage':
            if self.has_coverage_data() is False:
                return False
            sample_ids = [indiv.get_coverage_store_id() for indiv in self.get_individuals()]
            statuses = set(get_coverage_store().get_sample_statuses(sample_ids).values())

            # must be at least one fully loaded
            if 'loaded' not in statuses:
                return False

            # "there are no statuses other than loaded and None"
            return len(statuses.union({'loaded', None})) == 2
Esempio n. 9
0
def get_gene_diangostic_info(family, gene_id, variant_filter=None):

    diagnostic_info = GeneDiagnosticInfo(gene_id)

    diagnostic_info._gene_phenotype_summary = get_gene_phenotype_summary(
        get_reference(), gene_id)
    diagnostic_info._gene_sequencing_summary = get_gene_sequencing_summary(
        get_coverage_store(), family, gene_id)
    diagnostic_info._variants = get_diagnostic_search_variants_in_family(
        get_mall(family.project).variant_store, family, gene_id,
        variant_filter)
    diagnostic_info._cnvs = get_diagnostic_search_cnvs_in_family(
        get_cnv_store(),
        family,
        gene_id,
    )

    return diagnostic_info
Esempio n. 10
0
def get_gene_diangostic_info(family, gene_id, variant_filter=None):

    diagnostic_info = GeneDiagnosticInfo(gene_id)

    diagnostic_info._gene_phenotype_summary = get_gene_phenotype_summary(get_reference(), gene_id)
    diagnostic_info._gene_sequencing_summary = get_gene_sequencing_summary(get_coverage_store(), family, gene_id)
    diagnostic_info._variants = get_diagnostic_search_variants_in_family(
        get_mall(family.project).variant_store,
        family,
        gene_id,
        variant_filter
    )
    diagnostic_info._cnvs = get_diagnostic_search_cnvs_in_family(
        get_cnv_store(),
        family,
        gene_id,
    )

    return diagnostic_info
Esempio n. 11
0
def load_coverage_for_individuals(individuals):
    for individual in individuals:
        if individual.coverage_file:
            get_coverage_store().add_sample(
                individual.get_coverage_store_id(),
                gzip.open(individual.coverage_file))
Esempio n. 12
0
def load_coverage_for_individuals(individuals):
    for individual in individuals:
        if individual.coverage_file:
            get_coverage_store().add_sample(individual.get_coverage_store_id(), gzip.open(individual.coverage_file))