Esempio n. 1
0
    def get(self, request, *args, **kwargs):
        genome_build_name = self.kwargs['genome_build_name']
        variant_string = self.kwargs['variant_string']
        genome_build = GenomeBuild.get_name_or_alias(genome_build_name)
        variant = Variant.get_from_string(variant_string, genome_build)

        if variant is None:
            raise Http404(variant_string)

        vav = VariantAnnotationVersion.latest(genome_build)
        va = variant.variantannotation_set.get(version=vav)
        serializer = VariantAnnotationSerializer(va)
        return Response(serializer.data)
Esempio n. 2
0
def create_analysis_from_template(request, genome_build_name):
    data = request.POST.dict()
    tag_uuid = data.pop("tag_uuid")
    analysis_template_key = f"{tag_uuid}-analysis_template"
    analysis_template_name = data.pop(analysis_template_key)
    analysis_template = AnalysisTemplate.get_for_user(request.user,
                                                      analysis_template_name)

    genome_build = GenomeBuild.get_name_or_alias(genome_build_name)
    template_run = AnalysisTemplateRun.create(analysis_template,
                                              genome_build,
                                              user=request.user)
    template_run.populate_arguments(data)
    populate_analysis_from_template_run(template_run)

    return view_active_node(template_run.analysis, None)
Esempio n. 3
0
    def handle(self, *args, **options):
        f = sys.stdout

        genome_build = GenomeBuild.get_name_or_alias("GRCh37")
        header_lines = get_vcf_header_from_contigs(genome_build, {})
        for line in header_lines:
            f.write(line + '\n')

        num_variants = options["num_variants"]
        rows = []
        for _ in range(num_variants):
            ref = random_base()
            alt = random_base(not_base=ref)
            chrom = random_contig()
            pos = randrange(MAX_SIZE)
            rows.append([chrom, pos, '.', ref, alt, '.', '.', '.'])

        rows = sorted(rows, key=lambda x: (x[0], int(x[1])))
        for data in rows:
            line = '\t'.join(map(str, data))
            f.write(line + '\n')
Esempio n. 4
0
    def setUpClass(cls):
        super().setUpClass()

        user = User.objects.get_or_create(username='******')[0]
        cls.grch37 = GenomeBuild.get_name_or_alias("GRCh37")
        cls.annotation_version_grch37 = get_fake_annotation_version(cls.grch37)
        gene_annotation_release = cls.annotation_version_grch37.gene_annotation_version.gene_annotation_release
        cls.transcript_version = create_fake_transcript_version(cls.grch37,
                                                                release=gene_annotation_release)
        cls.gene_symbol = cls.transcript_version.gene_version.gene_symbol
        cls.trio = create_fake_trio(user, cls.grch37)

        cls.analysis = Analysis(genome_build=cls.grch37)
        cls.analysis.set_defaults_and_save(user)

        cls.sample = cls.trio.get_samples()[0]

        # Gene List
        cls.gene_list = GeneList.objects.get_or_create(name="fake list",
                                                       user=cls.analysis.user,
                                                       import_status=ImportStatus.SUCCESS)[0]
        GeneListGeneSymbol.objects.get_or_create(gene_list=cls.gene_list, gene_symbol=cls.gene_symbol)

        # Need some overlapping variants so gene list will work
        create_fake_variants(cls.grch37)
        # Note: Variant probably doesn't overlap with gene, just want a random one
        variant = Variant.objects.filter(Variant.get_no_reference_q()).first()
        annotation_run = AnnotationRun.objects.create()
        VariantGeneOverlap.objects.create(version=cls.annotation_version_grch37.variant_annotation_version,
                                          annotation_run=annotation_run,
                                          gene=cls.transcript_version.gene,
                                          variant=variant)

        # Tag that variant
        cls.tag = Tag.objects.get_or_create(pk="foo")[0]
        VariantTag.objects.create(genome_build=cls.grch37, analysis=cls.analysis,
                                  variant=variant, tag=cls.tag, user=user)
Esempio n. 5
0
def create_manual_variant_entry_from_text(request, genome_build_name,
                                          variants_text):
    genome_build = GenomeBuild.get_name_or_alias(genome_build_name)
    create_manual_variants(request.user, genome_build, variants_text)
    return redirect('manual_variant_entry')
Esempio n. 6
0
            variant_tag, created = VariantTag.objects.get_or_create(
                variant_id=variant_id,
                tag=tag,
                genome_build=genome_build,
                location=location,
                analysis=analysis,
                user=request.user)
            if node_id:
                variant_tag.node_id = node_id
                variant_tag.save()
        else:
            if genome_build_name is None:
                raise ValueError(
                    "Adding requires either 'analysis_id' or 'genome_build_name'"
                )
            genome_build = GenomeBuild.get_name_or_alias(genome_build_name)

            variant_tag, created = VariantTag.objects.get_or_create(
                variant_id=variant_id,
                tag=tag,
                analysis=None,
                location=location,
                user=request.user,
                defaults={"genome_build": genome_build})
        if created:  # Only return new if anything created
            ret = VariantTagSerializer(variant_tag,
                                       context={
                                           "request": request
                                       }).data
    elif op == 'del':
        # Deletion of tags is for analysis (all users)