Ejemplo n.º 1
0
    def test_import_panel_sources(self):
        gene = GeneFactory(gene_symbol="ABCC5-AS1")
        A1CF = GeneFactory(gene_symbol="A1CF")
        GeneFactory(gene_symbol="STR_1")

        gps = GenePanelSnapshotFactory()
        gps.panel.name = "Panel One"
        gps.level4title.name = gps.panel.name
        gps.level4title.save()
        gps.panel.save()
        evidence = EvidenceFactory.create(name="Expert Review Amber")
        GenePanelEntrySnapshotFactory.create(gene_core=gene,
                                             panel=gps,
                                             evaluation=(None, ),
                                             evidence=(evidence, ))
        self.assertEqual(
            gps.get_gene(gene.gene_symbol).evidence.first().name,
            "Expert Review Amber")

        file_path = os.path.join(os.path.dirname(__file__),
                                 'import_panel_data.tsv')
        test_panel_file = os.path.abspath(file_path)

        with open(test_panel_file) as f:
            url = reverse_lazy('panels:upload_panels')
            self.client.post(url, {'panel_list': f})

        ap = GenePanel.objects.get(name="Panel One").active_panel
        self.assertEqual(
            ap.get_gene(gene.gene_symbol).evidence.first().name,
            "Expert Review Green")
        self.assertEqual(ap.get_gene(gene.gene_symbol).evidence.count(), 1)
        self.assertEqual(sorted(ap.get_gene('A1CF').phenotypes),
                         sorted(['57h', 'wef']))
Ejemplo n.º 2
0
    def test_import_gene(self):
        """
        Test Gene import. This also tests CellBaseConnector, which actually makes
        requests to the server. We can mock it later if necessary.
        """

        file_path = os.path.join(os.path.dirname(__file__), 'test_import.json')
        test_gene_file = os.path.abspath(file_path)

        # Create genes to update
        update_symbol = []
        update = []
        with open(test_gene_file) as f:
            results = json.load(f)
            for r in results['update']:
                update.append(
                    GeneFactory(gene_symbol=r['gene_symbol']).gene_symbol)
            for r in results['update_symbol']:
                update_symbol.append(GeneFactory(gene_symbol=r[1]).gene_symbol)

        with open(test_gene_file) as f:
            url = reverse_lazy('panels:upload_genes')
            self.client.post(url, {'gene_list': f})

        for us in update_symbol:
            self.assertFalse(Gene.objects.get(gene_symbol=us).active)
        for u in update:
            gene = Gene.objects.get(gene_symbol=u)
            if gene.ensembl_genes:
                self.assertTrue(gene.active)
            else:
                self.assertFalse(gene.active)
Ejemplo n.º 3
0
    def test_adding_gene_save_source(self):
        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(4, panel=gps)
        gene = GeneFactory()

        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'gene'
                           })
        gene_data = {
            "gene":
            gene.pk,
            "source":
            Evidence.OTHER_SOURCES[0],
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        self.client.post(url, gene_data)
        gpes = gps.panel.active_panel.get_gene(gene.gene_symbol)
        self.assertTrue(gene_data['source'] in gpes.evaluation.get(
            user=self.verified_user).comments.first().comment)
Ejemplo n.º 4
0
    def test_adding_gene_create_activity(self):
        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(4, panel=gps)
        gene = GeneFactory()

        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'gene'
                           })
        gene_data = {
            "gene":
            gene.pk,
            "source":
            Evidence.OTHER_SOURCES[0],
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        req = self.client.post(url, gene_data)

        self.assertEqual(Activity.objects.count(), 1)
Ejemplo n.º 5
0
    def test_export_activities_functionality(self):
        gps = GenePanelSnapshotFactory()

        GenePanelEntrySnapshotFactory.create_batch(4, panel=gps)
        gene = GeneFactory()

        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'gene'
                           })
        gene_data = {
            "gene":
            gene.pk,
            "source":
            Evidence.OTHER_SOURCES[0],
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        self.client.post(url, gene_data)

        activities_url = reverse(
            'panels:activity') + '?format=csv&panel=' + str(gps.panel.pk)
        res = self.client.get(activities_url)
        self.assertTrue(gps.panel.name.encode() in res.content)
Ejemplo n.º 6
0
    def test_reviewer_source_visible(self):
        """When a reviewer adds a gene source should be displayed"""

        gene = GeneFactory()
        gps = GenePanelSnapshotFactory()
        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'gene'
                           })
        gene_data = {
            "gene":
            gene.pk,
            "source":
            Evidence.OTHER_SOURCES[2],
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        self.client.post(url, gene_data)

        url = reverse_lazy('panels:detail', kwargs={'pk': gps.panel.pk})
        res = self.client.get(url)
        self.assertContains(res, gene_data['source'])
Ejemplo n.º 7
0
    def test_update_gene_preserves_comments_order(self):
        gpes = GenePanelEntrySnapshotFactory()
        comments = list(CommentFactory.create_batch(4,
                                                    user=self.verified_user))

        for ev in gpes.evaluation.all():
            ev.comments.add(comments.pop())

        max_comments_num = max(
            [e.comments.count() for e in gpes.evaluation.all()])
        self.assertEqual(1, max_comments_num)

        old_gene_symbol = gpes.gene.get('gene_symbol')
        new_gene = GeneFactory()
        ap = GenePanel.objects.get(pk=gpes.panel.panel.pk).active_panel

        new_data = {"gene": new_gene, "gene_name": "Other name"}
        ap.update_gene(self.verified_user, old_gene_symbol, new_data)

        new_ap = GenePanel.objects.get(pk=gpes.panel.panel.pk).active_panel
        gpes = new_ap.get_gene(new_gene.gene_symbol)

        max_comments_num_after_update = max(
            [e.comments.count() for e in gpes.evaluation.all()])
        self.assertEqual(1, max_comments_num_after_update)
Ejemplo n.º 8
0
    def test_add_gene_to_panel(self):
        """When a reviewer adds a gene it shouldn't increment the version of a panel"""

        gene = GeneFactory()
        gps = GenePanelSnapshotFactory()
        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'gene'
                           })
        gene_data = {
            "gene":
            gene.pk,
            "source":
            Evidence.OTHER_SOURCES[0],
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        self.client.post(url, gene_data)
        panel = gps.panel.active_panel

        assert panel.version == gps.version
Ejemplo n.º 9
0
    def test_import_regions(self):
        GeneFactory(gene_symbol="ABCC5-AS1")
        GeneFactory(gene_symbol="A1CF")
        GeneFactory(gene_symbol="STR_1")

        file_path = os.path.join(os.path.dirname(__file__),
                                 'import_panel_data.tsv')
        test_panel_file = os.path.abspath(file_path)

        with open(test_panel_file) as f:
            url = reverse_lazy('panels:upload_panels')
            res = self.client.post(url, {'panel_list': f})

        gp = GenePanel.objects.get(name="Panel One")
        active_panel = gp.active_panel
        self.assertEqual(active_panel.get_all_regions.count(), 1)
Ejemplo n.º 10
0
    def test_get_panels_for_a_gene(self):
        gene = GeneFactory()

        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene, panel=gps)

        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene, panel=gps)

        gps3 = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps3)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene, panel=gps3)

        gps4 = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps4)  # random genes

        assert GenePanelEntrySnapshot.objects.get_gene_panels(
            gene.gene_symbol).count() == 3

        url = reverse_lazy('panels:entity_detail',
                           kwargs={'slug': gene.gene_symbol})
        res = self.client.get(url)
        assert len(res.context_data['entries']) == 3
Ejemplo n.º 11
0
    def test_get_internal_panels_for_a_gene(self):
        gene = GeneFactory()

        gps = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.public)
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene, panel=gps)

        gps2 = GenePanelSnapshotFactory(
            panel__status=GenePanel.STATUS.internal)
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps2)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene, panel=gps2)

        gps3 = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.public)
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps3)  # random genes

        self.assertEqual(
            GenePanelEntrySnapshot.objects.get_gene_panels(
                gene.gene_symbol).count(), 2)
        self.assertEqual(
            GenePanelSnapshot.objects.get_gene_panels(
                gene.gene_symbol).count(), 1)
        self.assertEqual(
            GenePanelSnapshot.objects.get_gene_panels(gene.gene_symbol,
                                                      all=True,
                                                      internal=True).count(),
            2)

        url = reverse_lazy('panels:entity_detail',
                           kwargs={'slug': gene.gene_symbol})
        res = self.client.get(url)
        self.assertEqual(len(res.context_data['entries']), 2)
Ejemplo n.º 12
0
    def test_gel_curator_str_red(self):
        """When gene is added by a GeL currator it should be marked as red"""

        gene = GeneFactory()
        gps = GenePanelSnapshotFactory()
        url = reverse_lazy('panels:add_entity', kwargs={'pk': gps.panel.pk, 'entity_type': 'str'})
        str_data = {
            'name': 'SomeSTR',
            'chromosome': '1',
            'position_37_0': '12345',
            'position_37_1': '12346',
            'position_38_0': '12345',
            'position_38_1': '123456',
            'repeated_sequence': 'ATAT',
            'normal_repeats': '2',
            'pathogenic_repeats': '5',
            "gene": gene.pk,
            "source": Evidence.OTHER_SOURCES[0],
            "phenotypes": "{};{};{}".format(*fake.sentences(nb=3)),
            "rating": Evaluation.RATINGS.AMBER,
            "moi": [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity": [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance": GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        self.client.post(url, str_data)
        panel = gps.panel.active_panel

        assert panel.get_str('SomeSTR').saved_gel_status == 1
Ejemplo n.º 13
0
    def test_reviewer_gene_grey(self):
        """When a reviewer adds a gene it should be marked as grey gene"""

        gene = GeneFactory()
        gps = GenePanelSnapshotFactory()
        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'gene'
                           })
        gene_data = {
            "gene":
            gene.pk,
            "source":
            Evidence.OTHER_SOURCES[0],
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        self.client.post(url, gene_data)
        panel = gps.panel.active_panel

        self.assertEqual(panel.get_gene(gene.gene_symbol).saved_gel_status, 0)
Ejemplo n.º 14
0
 def test_region_review_view(self):
     gene = GeneFactory()
     gps = GenePanelSnapshotFactory()
     region = RegionFactory(panel=gps, gene_core=gene)
     url = reverse_lazy('panels:review_entity', args=(region.panel.panel.pk, 'region', region.name,))
     r = self.client.get(url)
     self.assertEqual(r.status_code, 200)
Ejemplo n.º 15
0
 def test_gene_review_view(self):
     gene = GeneFactory()
     gps = GenePanelSnapshotFactory()
     gpes = GenePanelEntrySnapshotFactory(panel=gps, gene_core=gene)
     url = reverse_lazy('panels:review_entity',
                        args=(
                            gpes.panel.panel.pk,
                            'gene',
                            gene.gene_symbol,
                        ))
     r = self.client.get(url)
     self.assertEqual(r.status_code, 200)
Ejemplo n.º 16
0
    def test_download_panel(self):
        gene, gps, gps2 = self.prepare_compare()
        grey_gene = 'gene2'
        gene2 = GeneFactory(gene_symbol=grey_gene)
        gpes = GenePanelEntrySnapshotFactory.create(gene_core=gene2, panel=gps)
        gpes.saved_gel_status = 0

        res = self.client.get(
            reverse_lazy('panels:download_panel_tsv',
                         args=(gps.panel.pk, '01234')))
        self.assertEqual(res.status_code, 200)
        self.assertEqual(res.content.find(grey_gene.encode()), -1)
Ejemplo n.º 17
0
 def test_str_review_view(self):
     gene = GeneFactory()
     gps = GenePanelSnapshotFactory()
     str_item = STRFactory(panel=gps, gene_core=gene)
     url = reverse_lazy('panels:review_entity',
                        args=(
                            str_item.panel.panel.pk,
                            'str',
                            str_item.name,
                        ))
     r = self.client.get(url)
     self.assertEqual(r.status_code, 200)
Ejemplo n.º 18
0
    def test_add_region_to_panel(self):
        gene = GeneFactory()
        gps = GenePanelSnapshotFactory()

        number_of_regions = gps.stats.get('number_of_regions')

        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'region'
                           })
        region_data = {
            'name': 'SomeRegion',
            'chromosome': '1',
            'position_37_0': '',
            'position_37_1': '',
            'position_38_0': '12345',
            'position_38_1': '123456',
            'haploinsufficiency_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'triplosensitivity_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'required_overlap_percentage': randint(0, 100),
            "gene": gene.pk,
            "source": Evidence.ALL_SOURCES[randint(0, 9)],
            "tags": [
                TagFactory().pk,
            ],
            "publications": "{};{};{}".format(*fake.sentences(nb=3)),
            "phenotypes": "{};{};{}".format(*fake.sentences(nb=3)),
            "rating": Evaluation.RATINGS.AMBER,
            "comments": fake.sentence(),
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "penetrance": Region.PENETRANCE.Incomplete,
            "current_diagnostic": "True",
            "type_of_variants": Region.VARIANT_TYPES.small,
        }
        res = self.client.post(url, region_data)

        new_current_number = gps.panel.active_panel.stats.get(
            'number_of_regions')

        assert gps.panel.active_panel.version != gps.version

        assert res.status_code == 302
        assert number_of_regions + 1 == new_current_number

        # make sure tags are added
        new_region = GenePanel.objects.get(
            pk=gps.panel.pk).active_panel.get_region(region_data['name'])
        assert sorted(list(new_region.tags.all().values_list(
            'pk', flat=True))) == sorted(region_data['tags'])
Ejemplo n.º 19
0
    def test_edit_gene_name_ajax(self):
        gpes = GenePanelEntrySnapshotFactory()
        url = reverse_lazy('panels:edit_entity',
                           kwargs={
                               'pk': gpes.panel.panel.pk,
                               'entity_type': 'gene',
                               'entity_name': gpes.gene.get('gene_symbol')
                           })

        old_gene_symbol = gpes.gene.get('gene_symbol')

        # make sure new data has at least 1 of the same items
        source = gpes.evidence.last().name
        publication = gpes.publications[0]
        phenotype = gpes.publications[1]

        new_gene = GeneFactory()

        gene_data = {
            "gene":
            new_gene.pk,
            "gene_name":
            "Other name",
            "source":
            set([source, Evidence.ALL_SOURCES[randint(0, 9)]]),
            "tags": [
                TagFactory().pk,
            ] + [tag.pk for tag in gpes.tags.all()],
            "publications":
            ";".join([publication, fake.sentence()]),
            "phenotypes":
            ";".join([phenotype, fake.sentence(),
                      fake.sentence()]),
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        res = self.client.post(url, gene_data)
        assert res.status_code == 302

        new_gps = GenePanel.objects.get(pk=gpes.panel.panel.pk).active_panel
        old_gps = GenePanelSnapshot.objects.get(pk=gpes.panel.pk)

        # check panel has no previous gene
        assert new_gps.has_gene(old_gene_symbol) is False

        # test previous panel contains old gene
        assert old_gps.has_gene(old_gene_symbol) is True
Ejemplo n.º 20
0
    def test_gel_curator_region_red(self):
        """When gene is added by a GeL currator it should be marked as red"""

        gene = GeneFactory()
        gps = GenePanelSnapshotFactory()
        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'region'
                           })
        region_data = {
            'name':
            'SomeRegion',
            'chromosome':
            '1',
            'position_37_0':
            '12345',
            'position_37_1':
            '12346',
            'position_38_0':
            '12345',
            'position_38_1':
            '123456',
            'haploinsufficiency_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'triplosensitivity_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'required_overlap_percentage':
            randint(0, 100),
            "gene":
            gene.pk,
            "source":
            Evidence.OTHER_SOURCES[0],
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            Region.PENETRANCE.Incomplete,
            "type_of_variants":
            Region.VARIANT_TYPES.small,
        }
        self.client.post(url, region_data)
        panel = gps.panel.active_panel

        assert panel.get_region('SomeRegion').saved_gel_status == 1
Ejemplo n.º 21
0
    def test_edit_gene_name_unit(self):
        gpes = GenePanelEntrySnapshotFactory()
        old_gene_symbol = gpes.gene.get('gene_symbol')
        new_gene = GeneFactory()

        ap = GenePanel.objects.get(pk=gpes.panel.panel.pk).active_panel

        assert ap.has_gene(old_gene_symbol) is True
        new_data = {"gene": new_gene, "gene_name": "Other name"}
        ap.update_gene(self.verified_user, old_gene_symbol, new_data)

        new_ap = GenePanel.objects.get(pk=gpes.panel.panel.pk).active_panel
        assert new_ap.has_gene(old_gene_symbol) is False
        assert new_ap.has_gene(new_gene.gene_symbol) is True
Ejemplo n.º 22
0
    def prepare_compare(self):
        gene = GeneFactory()

        gps = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.internal)
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene, panel=gps)

        gps2 = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.public)
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps2)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene, panel=gps2)

        STRFactory(panel=gps, position_37=None)

        return gene, gps, gps2
Ejemplo n.º 23
0
    def test_import_incorrect_position(self):
        GeneFactory(gene_symbol="STR_1")

        file_path = os.path.join(os.path.dirname(__file__),
                                 'import_panel_data_error.tsv')
        test_panel_file = os.path.abspath(file_path)

        with open(test_panel_file) as f:
            url = reverse_lazy('panels:upload_panels')
            res = self.client.post(url, {'panel_list': f})
            messages = [str(m) for m in res.wsgi_request._messages]
            expected_messages = [
                'Line: 3, 4, 5 is not properly formatted, please check it and try again.'
            ]
            self.assertEqual(expected_messages, messages)

        self.assertEqual(GenePanel.objects.count(), 0)
Ejemplo n.º 24
0
    def test_activate_genes_output(self):
        out = StringIO()

        GeneFactory.create_batch(3, active=True)
        GeneFactory.create_batch(4, active=False, ensembl_genes='{}')
        GeneFactory.create_batch(5,
                                 active=False,
                                 ensembl_genes='{"hello": "world"}')

        call_command('activate_genes', stdout=out)
        self.assertIn('5 genes should be active', out.getvalue())
        self.assertEqual(8, Gene.objects.filter(active=True).count())
Ejemplo n.º 25
0
    def test_add_gene_to_panel(self):
        gene = GeneFactory()
        gps = GenePanelSnapshotFactory()

        number_of_genes = gps.stats.get('number_of_genes', 0)

        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'gene'
                           })
        gene_data = {
            "gene":
            gene.pk,
            "source":
            Evidence.ALL_SOURCES[randint(0, 9)],
            "tags": [
                TagFactory().pk,
            ],
            "publications":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "comments":
            fake.sentence(),
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
            "current_diagnostic":
            "True"
        }
        res = self.client.post(url, gene_data)

        new_current_number = gps.panel.active_panel.stats.get(
            'number_of_genes', 0)

        assert gps.panel.active_panel.version != gps.version

        assert res.status_code == 302
        assert number_of_genes + 1 == new_current_number
Ejemplo n.º 26
0
    def test_filter_by_panel_date_range(self):
        gps = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.public)
        GenePanelEntrySnapshotFactory.create_batch(4, panel=gps)
        gene = GeneFactory()
        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'gene'
                           })
        gene_data = {
            "gene":
            gene.pk,
            "source":
            Evidence.OTHER_SOURCES[0],
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        self.client.post(url, gene_data)

        now = timezone.now()
        date_from = (now - timedelta(days=7)).strftime('%Y-%m-%d')
        date_to = (now + timedelta(days=7)).strftime('%Y-%m-%d')
        activities_url = reverse(
            'panels:activity'
        ) + '?date_from=' + date_from + '&date_to=' + date_to
        res = self.client.get(activities_url)
        self.assertEqual(len(res.context['activities']), 1)

        now = timezone.now() - timedelta(days=30)
        date_from = (now - timedelta(days=7)).strftime('%Y-%m-%d')
        date_to = (now + timedelta(days=7)).strftime('%Y-%m-%d')
        activities_url = reverse(
            'panels:activity'
        ) + '?date_from=' + date_from + '&date_to=' + date_to
        res = self.client.get(activities_url)
        self.assertEqual(len(res.context['activities']), 0)
Ejemplo n.º 27
0
    def test_mitochondrial_gene(self):
        gene = GeneFactory(gene_symbol="MT-LORUM")
        gpes = GenePanelEntrySnapshotFactory(gene_core=gene)
        url = reverse_lazy('panels:edit_entity',
                           kwargs={
                               'pk': gpes.panel.panel.pk,
                               'entity_type': 'gene',
                               'entity_name': gpes.gene.get('gene_symbol')
                           })

        # make sure new data has at least 1 of the same items

        gpes.publications[0]
        gpes.publications[1]

        gene_data = {
            "gene":
            gpes.gene_core.pk,
            "gene_name":
            "Gene name",
            "source": [ev.name for ev in gpes.evidence.all()],
            "tags": [
                TagFactory().pk,
            ] + [tag.pk for tag in gpes.tags.all()],
            "publications":
            ";".join(gpes.publications),
            "phenotypes":
            ";".join(gpes.phenotypes),
            "moi":
            gpes.moi,
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        res = self.client.post(url, gene_data)
        assert res.status_code == 302
        gene = GenePanel.objects.get(
            pk=gpes.panel.panel.pk).active_panel.get_gene(
                gpes.gene_core.gene_symbol)
        assert gene.moi == "MITOCHONDRIAL"
Ejemplo n.º 28
0
    def test_import_reviews(self):
        gene = GeneFactory(gene_symbol="ABCC5-AS1")
        gps = GenePanelSnapshotFactory()
        current_version = gps.version
        gps.panel.name = "Panel One"
        gps.panel.save()
        GenePanelEntrySnapshotFactory.create(gene_core=gene,
                                             panel=gps,
                                             evaluation=(None, ))

        file_path = os.path.join(os.path.dirname(__file__),
                                 'import_reviews_data.tsv')
        test_reviews_file = os.path.abspath(file_path)

        with open(test_reviews_file) as f:
            url = reverse_lazy('panels:upload_reviews')
            self.client.post(url, {'review_list': f})

        ap = GenePanel.objects.get(name="Panel One").active_panel
        assert ap.get_gene(gene.gene_symbol).evaluation.count() == 1
        assert current_version != ap.version
Ejemplo n.º 29
0
    def test_add_str_to_panel(self):
        gene = GeneFactory()
        gps = GenePanelSnapshotFactory()

        number_of_strs = gps.stats.get('number_of_strs', 0)

        url = reverse_lazy('panels:add_entity', kwargs={'pk': gps.panel.pk, 'entity_type': 'str'})
        gene_data = {
            'name': 'SomeSTR',
            'chromosome': '1',
            'position_37_0': '',
            'position_37_1': '',
            'position_38_0': '12345',
            'position_38_1': '123456',
            'repeated_sequence': 'ATAT',
            'normal_repeats': '2',
            'pathogenic_repeats': '5',
            "gene": gene.pk,
            "source": Evidence.ALL_SOURCES[randint(0, 9)],
            "tags": [TagFactory().pk, ],
            "publications": "{};{};{}".format(*fake.sentences(nb=3)),
            "phenotypes": "{};{};{}".format(*fake.sentences(nb=3)),
            "rating": Evaluation.RATINGS.AMBER,
            "comments": fake.sentence(),
            "moi": [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "penetrance": GenePanelEntrySnapshot.PENETRANCE.Incomplete,
            "current_diagnostic": "True"
        }
        res = self.client.post(url, gene_data)

        new_current_number = gps.panel.active_panel.stats.get('number_of_strs')

        assert gps.panel.active_panel.version != gps.version

        assert res.status_code == 302
        assert number_of_strs + 1 == new_current_number

        # make sure tags are added
        new_str = GenePanel.objects.get(pk=gps.panel.pk).active_panel.get_str(gene_data['name'])
        assert sorted(list(new_str.tags.all().values_list('pk', flat=True))) == sorted(gene_data['tags'])
Ejemplo n.º 30
0
    def test_filter_by_panel_entity(self):
        gps = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.public)
        GenePanelEntrySnapshotFactory.create_batch(4, panel=gps)
        gene = GeneFactory()
        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'gene'
                           })
        gene_data = {
            "gene":
            gene.pk,
            "source":
            Evidence.OTHER_SOURCES[0],
            "phenotypes":
            "{};{};{}".format(*fake.sentences(nb=3)),
            "rating":
            Evaluation.RATINGS.AMBER,
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity":
            [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
            "penetrance":
            GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        self.client.post(url, gene_data)

        activities_url = reverse(
            'panels:activity'
        ) + '?entity=' + gene.gene_symbol + '&version=0.0&panel=' + str(
            gps.panel.pk)
        res = self.client.get(activities_url)
        self.assertEqual(len(res.context['activities']), 1)

        activities_url = reverse(
            'panels:activity') + '?entity=ABCD&version=0.0&panel=' + str(
                gps.panel.pk)
        res = self.client.get(activities_url)
        self.assertEqual(len(res.context['activities']), 0)