Exemplo n.º 1
0
    def test_add_evaluation_comments_only(self):
        """Add comments"""

        str_item = STRFactory()
        current_version = str_item.panel.version
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:review_entity',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        str_data = {
            "comments": fake.sentence(),
        }
        res = self.client.post(url, str_data)
        assert res.status_code == 302

        v01gene = str_item.panel.panel.active_panel.get_str(str_item.name)
        assert v01gene.evaluation.get(user=self.gel_user).comments.count() == 1

        str_data = {
            "comments": fake.sentence(),
        }
        res = self.client.post(url, str_data)

        assert v01gene.evaluation.get(user=self.gel_user).comments.count() == 2
        assert current_version == str_item.panel.panel.active_panel.version
Exemplo n.º 2
0
    def test_change_penetrance(self):
        """Test if a curator can change Gene penetrance"""

        str_item = STRFactory(
            penetrance=GenePanelEntrySnapshot.PENETRANCE.Incomplete
        )
        url = reverse_lazy('panels:edit_entity', kwargs={
            'pk': str_item.panel.panel.pk,
            'entity_type': 'str',
            'entity_name': str_item.name
        })

        str_data = {
            'name': str_item.name,
            '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": str_item.gene_core.pk,
            "gene_name": "Gene name",
            "source": set([ev.name for ev in str_item.evidence.all()]),
            "tags": [tag.pk for tag in str_item.tags.all()],
            "publications": ";".join([publication for publication in str_item.publications]),
            "phenotypes": ";".join([phenotype for phenotype in str_item.phenotypes]),
            "moi": str_item.moi,
            "penetrance": GenePanelEntrySnapshot.PENETRANCE.Complete,
        }
        res = self.client.post(url, str_data)
        assert res.status_code == 302
        new_str = GenePanel.objects.get(pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert new_str.penetrance != str_item.penetrance
Exemplo n.º 3
0
    def test_form_should_be_prefilled(self):
        str_item = STRFactory()
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:review_entity',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        str_data = {
            "rating":
            Evaluation.RATINGS.AMBER,
            "current_diagnostic":
            True,
            "publications":
            ";".join([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],
        }

        self.client.post(url, str_data)

        url = reverse_lazy('panels:evaluation',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })
        res = self.client.get(url)
        assert res.content.find(
            str.encode('<option value="{}" selected>'.format(
                str_data['moi']))) != -1
Exemplo n.º 4
0
    def test_update_rating(self):
        str_item = STRFactory()
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_rating',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        new_status = 0
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url,
                               data,
                               HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 1
        assert res.content.find(str.encode(data['comment'])) != -1
        assert gene.saved_gel_status == new_status

        new_status = 1
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url,
                               data,
                               HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count(
        ) == 3  # FIXME old comments are deleted even for the current object...
        assert gene.saved_gel_status == new_status

        new_status = 2
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url,
                               data,
                               HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 6
        assert gene.saved_gel_status == new_status

        new_status = 3
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url,
                               data,
                               HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 10
        assert gene.saved_gel_status == new_status
        assert gene.panel.version != str_item.panel.version
Exemplo n.º 5
0
    def test_download_panel_contains_strs(self):
        gpes = GenePanelEntrySnapshotFactory()
        gps = gpes.panel
        strs = STRFactory(repeated_sequence="ATATCGCGN", panel=gps)

        res = self.client.get(reverse_lazy('panels:download_panel_tsv', args=(gps.panel.pk, '01234')))
        self.assertEqual(res.status_code, 200)
        self.assertTrue(res.content.find(strs.repeated_sequence.encode()) != 1)
Exemplo n.º 6
0
 def test_str_evaluation(self):
     str_item = STRFactory()
     url = reverse_lazy('panels:evaluation', kwargs={
         'pk': str_item.panel.panel.pk,
         'entity_type': 'str',
         'entity_name': str_item.name
     })
     res = self.client.get(url)
     assert res.status_code == 200
Exemplo n.º 7
0
    def test_user_reviews(self):
        gps = GenePanelSnapshotFactory()
        str_item = STRFactory.create_batch(10, panel=gps)
        for g in str_item:
            for evaluation in g.evaluation.all():
                evaluation.user = self.verified_user
                evaluation.save()

        self.assertEqual(self.verified_user.get_recent_evaluations().count(),
                         35)
Exemplo n.º 8
0
    def test_delete_comment(self):
        str_item = STRFactory()
        current_version = str_item.panel.version

        evaluation_url = reverse_lazy('panels:review_entity',
                                      kwargs={
                                          'pk': str_item.panel.panel.pk,
                                          'entity_type': 'str',
                                          'entity_name': str_item.name
                                      })

        gene_data = {
            "rating":
            Evaluation.RATINGS.AMBER,
            "current_diagnostic":
            True,
            "comments":
            fake.sentence(),
            "publications":
            ";".join([fake.sentence(), fake.sentence()]),
            "phenotypes":
            ";".join([fake.sentence(),
                      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],
        }
        self.client.post(evaluation_url,
                         gene_data,
                         HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        evaluation = gene.evaluation.get(user=self.gel_user)

        assert evaluation.comments.count() == 1

        delete_comment_url = reverse_lazy('panels:delete_comment_by_user',
                                          kwargs={
                                              'pk':
                                              str_item.panel.panel.pk,
                                              'entity_type':
                                              'str',
                                              'entity_name':
                                              str_item.name,
                                              'comment_pk':
                                              evaluation.comments.first().pk
                                          })
        res = self.client.get(delete_comment_url,
                              HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        assert res.json().get('status') == 200
        assert evaluation.comments.count() == 0
        assert res.content.find(str.encode('Your review')) != -1
        assert current_version == str_item.panel.panel.active_panel.version
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def setUp(self):
     super().setUp()
     self.gps = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.public)
     self.gps_public = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.public)
     self.gpes = GenePanelEntrySnapshotFactory(panel=self.gps_public)
     self.gpes_internal = GenePanelEntrySnapshotFactory(panel__panel__status=GenePanel.STATUS.internal)
     self.gpes_retired = GenePanelEntrySnapshotFactory(panel__panel__status=GenePanel.STATUS.retired)
     self.gpes_deleted = GenePanelEntrySnapshotFactory(panel__panel__status=GenePanel.STATUS.deleted)
     self.genes = GenePanelEntrySnapshotFactory.create_batch(4, panel=self.gps)
     self.str = STRFactory(panel__panel__status=GenePanel.STATUS.public)
     self.region = RegionFactory(panel__panel__status=GenePanel.STATUS.public)
     self.region2 = RegionFactory(panel__panel__status=GenePanel.STATUS.public, position_37=None)
Exemplo n.º 11
0
    def test_mark_as_ready_no_gene(self):
        str_item = STRFactory(gene=None)
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:mark_entity_as_ready',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        self.client.post(url, {'ready_comment': fake.sentence()})
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert gene.ready is True
Exemplo n.º 12
0
    def test_edit_str_name_unit(self):
        str_item = STRFactory()
        old_str_name = str_item.name

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

        assert ap.has_str(old_str_name) is True
        new_data = {
            "name": 'NewSTR'
        }
        ap.update_str(self.verified_user, old_str_name, new_data)

        new_ap = GenePanel.objects.get(pk=str_item.panel.panel.pk).active_panel
        assert new_ap.has_str(old_str_name) is False
        assert new_ap.has_str('NewSTR') is True
Exemplo n.º 13
0
    def test_remove_gene_from_str(self):
        """We need ability to remove genes from STRs"""

        str_item = STRFactory()
        url = reverse_lazy('panels:edit_entity', kwargs={
            'pk': str_item.panel.panel.pk,
            'entity_type': 'str',
            'entity_name': str_item.name
        })

        number_of_strs = str_item.panel.stats.get('number_of_strs', 0)

        # make sure new data has at least 1 of the same items
        source = str_item.evidence.last().name

        publication = str_item.publications[0]
        phenotype = str_item.publications[1]

        new_evidence = Evidence.ALL_SOURCES[randint(0, 9)]
        original_evidences = set([ev.name for ev in str_item.evidence.all()])
        original_evidences.add(new_evidence)

        str_data = {
            'name': str_item.name,
            '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_name": "Gene name",
            "source": set([source, new_evidence]),
            "tags": [TagFactory().pk, ] + [tag.pk for tag in str_item.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],
            "penetrance": GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        res = self.client.post(url, str_data)
        assert res.status_code == 302
        new_str = GenePanel.objects.get(pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert not new_str.gene_core
        assert not new_str.gene
        assert str_item.panel.panel.active_panel.version != str_item.panel.version
        new_current_number = new_str.panel.panel.active_panel.stats.get('number_of_strs')
        assert number_of_strs == new_current_number
Exemplo n.º 14
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
Exemplo n.º 15
0
    def test_edit_str_name_ajax(self):
        str_item = STRFactory()
        url = reverse_lazy('panels:edit_entity', kwargs={
            'pk': str_item.panel.panel.pk,
            'entity_type': 'str',
            'entity_name': str_item.name
        })

        old_str_name = str_item.name

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

        gene_data = {
            'name': 'NewSTR',
            '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": str_item.gene_core.pk,
            "gene_name": "Other name",
            "source": set([source, Evidence.ALL_SOURCES[randint(0, 9)]]),
            "tags": [TagFactory().pk, ] + [tag.pk for tag in str_item.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],
            "penetrance": GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        res = self.client.post(url, gene_data)
        assert res.status_code == 302

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

        # check panel has no previous gene
        assert new_gps.has_str(old_str_name) is False

        # test previous panel contains old gene
        assert old_gps.has_str(old_str_name) is True
Exemplo n.º 16
0
    def test_change_evaluation(self):
        str_item = STRFactory()
        current_version = str_item.panel.version
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:review_entity',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        old_phenotypes = [fake.sentence(), fake.sentence(), fake.sentence()]
        gene_data = {
            "rating":
            Evaluation.RATINGS.AMBER,
            "current_diagnostic":
            True,
            "comments":
            fake.sentence(),
            "publications":
            ";".join([fake.sentence(), fake.sentence()]),
            "phenotypes":
            ";".join(old_phenotypes),
            "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],
        }
        self.client.post(url, gene_data)
        assert Evaluation.objects.filter(user=self.gel_user).count() == 1

        gene_data = {
            "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],
        }
        self.client.post(url, gene_data)
        assert Evaluation.objects.filter(user=self.gel_user).count() == 1
        assert Evaluation.objects.get(
            user=self.gel_user).phenotypes == old_phenotypes
        assert current_version == str_item.panel.panel.active_panel.version
Exemplo n.º 17
0
    def test_edit_incorrect_repeated_sequence(self):
        str_item = STRFactory()
        url = reverse_lazy('panels:edit_entity', kwargs={
            'pk': str_item.panel.panel.pk,
            'entity_type': 'str',
            'entity_name': str_item.name
        })

        number_of_strs = str_item.panel.stats.get('number_of_strs')

        # make sure new data has at least 1 of the same items
        source = str_item.evidence.last().name

        publication = str_item.publications[0]
        phenotype = str_item.publications[1]

        new_evidence = Evidence.ALL_SOURCES[randint(0, 9)]
        original_evidences = set([ev.name for ev in str_item.evidence.all()])
        original_evidences.add(new_evidence)

        str_data = {
            'name': str_item.name,
            'chromosome': '1',
            'position_37_0': '12345',
            'position_37_1': '12346',
            'position_38_0': '12345',
            'position_38_1': '123456',
            'repeated_sequence': 'ATATBC',
            'normal_repeats': '2',
            'pathogenic_repeats': '5',
            "gene": str_item.gene_core.pk,
            "gene_name": "Gene name",
            "source": set([source, new_evidence]),
            "tags": [TagFactory().pk, ] + [tag.pk for tag in str_item.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],
            "penetrance": GenePanelEntrySnapshot.PENETRANCE.Incomplete,
        }
        res = self.client.post(url, str_data)
        assert res.status_code == 200
        assert res.content.find(b'Repeated sequence contains incorrect nucleotides') != -1
Exemplo n.º 18
0
    def test_add_evaluation(self):
        """Add an evaluation"""

        str_item = STRFactory()
        str_item.evaluation.all().delete()
        str_item.panel.update_saved_stats()
        url = reverse_lazy('panels:review_entity',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        current_version = str_item.panel.version

        number_of_evaluated_genes = str_item.panel.stats.get(
            'number_of_evaluated_strs')

        str_data = {
            "rating":
            Evaluation.RATINGS.AMBER,
            "current_diagnostic":
            True,
            "comments":
            fake.sentence(),
            "publications":
            ";".join([fake.sentence(), fake.sentence()]),
            "phenotypes":
            ";".join([fake.sentence(),
                      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],
        }
        res = self.client.post(url, str_data)
        assert res.status_code == 302
        assert number_of_evaluated_genes + 1 == str_item.panel.panel.active_panel.stats.get(
            'number_of_evaluated_strs')
        assert current_version == str_item.panel.panel.active_panel.version
Exemplo n.º 19
0
    def test_update_tags(self):
        str_item = STRFactory()
        current_version = str_item.panel.version
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_tags',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        tag1 = TagFactory()
        tag2 = TagFactory()

        res = self.client.post(url, {'tags': [tag1.pk, tag2.pk]},
                               HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert res.json().get('status') == 200
        assert gene.tags.count() == 2
        assert current_version == str_item.panel.panel.active_panel.version
Exemplo n.º 20
0
    def test_curator_comment_added(self):
        str_item = STRFactory()
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_rating',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        new_status = 0
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url,
                               data,
                               HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)

        assert res.content.find(str.encode(data['comment'])) != -1
        assert gene.evaluation.count() > 0
Exemplo n.º 21
0
    def test_add_review_after_comment(self):
        """When you add a comment and then want to add a review it should be logged"""

        str_item = STRFactory()
        current_version = str_item.panel.version
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:review_entity',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        gene_data = {
            "comments": fake.sentence(),
        }
        res = self.client.post(url, gene_data)
        assert res.status_code == 302

        v01gene = str_item.panel.panel.active_panel.get_str(str_item.name)
        assert v01gene.evaluation.get(user=self.gel_user).comments.count() == 1

        review_data = {
            "rating": Evaluation.RATINGS.AMBER,
            "current_diagnostic": True,
            "comments": fake.sentence(),
            "publications": ";".join([fake.sentence(),
                                      fake.sentence()]),
        }
        url_review = reverse_lazy('panels:review_entity',
                                  kwargs={
                                      'pk': str_item.panel.panel.pk,
                                      'entity_type': 'str',
                                      'entity_name': str_item.name
                                  })
        self.client.post(url_review, review_data)
        res_review = self.client.get(url_review)
        assert res_review.content.find(str.encode(
            review_data['publications'])) != -1
        assert current_version == str_item.panel.panel.active_panel.version
Exemplo n.º 22
0
    def test_update_moi(self):
        str_item = STRFactory()
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_moi',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        moi = [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 2)]
        data = {'comment': fake.sentence(), 'moi': moi[1]}

        res = self.client.post(url,
                               data,
                               HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 1
        assert gene.moi == moi[1]
        assert gene.panel.version != str_item.panel.version
Exemplo n.º 23
0
    def test_remove_tag_via_edit_details(self):
        """Remove tags via edit gene detail section"""

        str_item = STRFactory(
            penetrance=GenePanelEntrySnapshot.PENETRANCE.Incomplete
        )

        tag = TagFactory(name='some tag')
        str_item.tags.add(tag)

        url = reverse_lazy('panels:edit_entity', kwargs={
            'pk': str_item.panel.panel.pk,
            'entity_type': 'str',
            'entity_name': str_item.name
        })

        str_data = {
            'name': str_item.name,
            '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": str_item.gene_core.pk,
            "gene_name": "Gene name",
            "source": set([ev.name for ev in str_item.evidence.all()]),
            "tags": [],
            "publications": ";".join([publication for publication in str_item.publications]),
            "phenotypes": ";".join([phenotype for phenotype in str_item.phenotypes]),
            "moi": str_item.moi,
            "penetrance": GenePanelEntrySnapshot.PENETRANCE.Complete,
        }
        res = self.client.post(url, str_data)
        assert res.status_code == 302
        new_str = GenePanel.objects.get(pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert list(new_str.tags.all()) == []
Exemplo n.º 24
0
    def test_update_phenotypes(self):
        str_item = STRFactory()
        str_item.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_phenotypes',
                           kwargs={
                               'pk': str_item.panel.panel.pk,
                               'entity_type': 'str',
                               'entity_name': str_item.name
                           })

        phenotypes_array = [fake.word(), fake.word()]
        phenotypes = "{}; {}".format(phenotypes_array[0], phenotypes_array[1])
        data = {'comment': fake.sentence(), 'phenotypes': phenotypes}

        res = self.client.post(url,
                               data,
                               HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 1
        assert gene.phenotypes == phenotypes_array
        assert gene.panel.version != str_item.panel.version
Exemplo n.º 25
0
    def test_update_str_preserves_comments_order(self):
        str_item = STRFactory()
        comments = list(CommentFactory.create_batch(4, user=self.verified_user))

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

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

        old_str_name = str_item.name
        ap = GenePanel.objects.get(pk=str_item.panel.panel.pk).active_panel

        new_data = {
            "name": 'NewSTR'
        }
        ap.update_str(self.verified_user, old_str_name, new_data)

        new_ap = GenePanel.objects.get(pk=str_item.panel.panel.pk).active_panel
        new_str = new_ap.get_str('NewSTR')

        max_comments_num_after_update = max([e.comments.count() for e in new_str.evaluation.all()])
        self.assertEqual(1, max_comments_num_after_update)
Exemplo n.º 26
0
    def test_update_ensembl(self):
        gene_symbol = 'FAM58A'
        gene_to_update = GeneFactory(gene_symbol=gene_symbol)
        ensembl_data = {
            "GRch37": {
                "82": {
                    "ensembl_id": "ENSG00000147382",
                    "location": "X:152853377-152865500"
                }
            },
            "GRch38": {
                "90": {
                    "ensembl_id": "ENSG00000262919",
                    "location": "X:153587919-153600045"
                }
            }
        }
        json_data = {gene_symbol: ensembl_data}

        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene_to_update,
                                             panel=gps)
        STRFactory.create_batch(2, panel=gps)  # random STRs
        STRFactory.create(gene_core=gene_to_update, panel=gps)
        RegionFactory.create_batch(2, panel=gps)  # random STRs
        RegionFactory.create(gene_core=gene_to_update, panel=gps)

        gps_2 = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps_2)  # random genes
        STRFactory.create_batch(2, panel=gps_2)  # random STRs
        RegionFactory.create_batch(2, panel=gps_2)  # random STRs
        RegionFactory.create(gene_core=gene_to_update, panel=gps_2)

        # make sure ensembl data doesn't match
        for gene in GenePanelEntrySnapshot.objects.filter(
                gene__gene_symbol=gene_symbol):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for str in STR.objects.filter(gene__gene_symbol=gene_symbol):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for region in Region.objects.filter(gene__gene_symbol=gene_symbol):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        gps_pk = gps.pk
        gps_version = gps.version
        gps_2_version = gps_2.version

        process(json_data)

        # make sure previous data didn't change
        for gene in GenePanelEntrySnapshot.objects.filter(
                gene__gene_symbol=gene_symbol, panel_id=gps_pk):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for str in STR.objects.filter(gene__gene_symbol=gene_symbol,
                                      panel_id=gps_pk):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for region in Region.objects.filter(gene__gene_symbol=gene_symbol,
                                            panel_id=gps_pk):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        gps = gps.panel.active_panel
        gps_2 = gps_2.panel.active_panel

        self.assertNotEqual(gps_version, gps.version)
        self.assertNotEqual(gps_2_version, gps_2.version)

        # make sure new data has changed
        for gene in GenePanelEntrySnapshot.objects.filter(
                gene__gene_symbol=gene_symbol, panel=gps):
            self.assertEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for str in STR.objects.filter(gene__gene_symbol=gene_symbol,
                                      panel=gps):
            self.assertEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for region in Region.objects.filter(gene__gene_symbol=gene_symbol,
                                            panel=gps):
            self.assertEqual(gene.gene.get('ensembl_genes'), ensembl_data)
Exemplo n.º 27
0
    def test_update_gene_collection(self):
        gene_to_update = GeneFactory()
        gene_to_delete = GeneFactory()
        gene_to_update_symbol = GeneFactory()

        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene_to_update,
                                             panel=gps)
        STRFactory.create_batch(2, panel=gps)  # random STRs
        STRFactory.create(gene_core=gene_to_update, panel=gps)
        RegionFactory.create_batch(2, panel=gps)  # random STRs
        RegionFactory.create(gene_core=gene_to_update, panel=gps)

        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        STRFactory.create_batch(2, panel=gps)  # random STRs
        GenePanelEntrySnapshotFactory.create(gene_core=gene_to_update_symbol,
                                             panel=gps)
        STRFactory.create(gene_core=gene_to_update_symbol, panel=gps)
        RegionFactory.create_batch(2, panel=gps)  # random STRs
        RegionFactory.create(gene_core=gene_to_update_symbol, panel=gps)

        to_insert = [
            Gene(gene_symbol='A', ensembl_genes={
                'inserted': True
            }).dict_tr(),
            Gene(gene_symbol='B', ensembl_genes={
                'inserted': True
            }).dict_tr(),
        ]

        to_update = [
            Gene(gene_symbol=gene_to_update.gene_symbol,
                 ensembl_genes={
                     'updated': True
                 }).dict_tr()
        ]

        to_update_symbol = [(Gene(gene_symbol='C',
                                  ensembl_genes={
                                      'updated': True
                                  }).dict_tr(),
                             gene_to_update_symbol.gene_symbol)]

        to_delete = [gene_to_delete.gene_symbol]

        migration = {
            'insert': to_insert,
            'update': to_update,
            'delete': to_delete,
            'update_symbol': to_update_symbol
        }

        update_gene_collection(migration)

        self.assertTrue(GenePanelEntrySnapshot.objects.get_active().get(
            gene_core__gene_symbol=gene_to_update.gene_symbol).gene.get(
                'ensembl_genes')['updated'])

        self.assertTrue(STR.objects.get_active().get(
            gene_core__gene_symbol=gene_to_update.gene_symbol).gene.get(
                'ensembl_genes')['updated'])

        self.assertTrue(Region.objects.get_active().get(
            gene_core__gene_symbol=gene_to_update.gene_symbol).gene.get(
                'ensembl_genes')['updated'])

        updated_not_updated = [
            gpes.gene['ensembl_genes']
            for gpes in GenePanelEntrySnapshot.objects.filter(
                gene_core__gene_symbol=gene_to_update.gene_symbol)
        ]
        self.assertNotEqual(updated_not_updated[0], updated_not_updated[1])

        updated_not_updated = [
            str_item.gene['ensembl_genes'] for str_item in STR.objects.filter(
                gene_core__gene_symbol=gene_to_update.gene_symbol)
        ]
        self.assertNotEqual(updated_not_updated[0], updated_not_updated[1])

        updated_not_updated = [
            region_item.gene['ensembl_genes']
            for region_item in Region.objects.filter(
                gene_core__gene_symbol=gene_to_update.gene_symbol)
        ]
        self.assertNotEqual(updated_not_updated[0], updated_not_updated[1])

        self.assertFalse(
            GenePanelEntrySnapshot.objects.get(
                gene_core__gene_symbol=gene_to_update_symbol.gene_symbol).
            gene_core.active)

        self.assertFalse(
            STR.objects.get(gene_core__gene_symbol=gene_to_update_symbol.
                            gene_symbol).gene_core.active)

        self.assertFalse(
            Region.objects.get(gene_core__gene_symbol=gene_to_update_symbol.
                               gene_symbol).gene_core.active)

        self.assertFalse(
            Gene.objects.get(
                gene_symbol=gene_to_update_symbol.gene_symbol).active)
        self.assertFalse(
            Gene.objects.get(gene_symbol=gene_to_delete.gene_symbol).active)
        self.assertTrue(Gene.objects.get(gene_symbol='A').active)

        self.assertTrue(
            GenePanelEntrySnapshot.objects.get(gene_core__gene_symbol='C').
            gene.get('ensembl_genes')['updated'])

        self.assertTrue(
            STR.objects.get(gene_core__gene_symbol='C').gene.get(
                'ensembl_genes')['updated'])

        self.assertTrue(
            Region.objects.get(gene_core__gene_symbol='C').gene.get(
                'ensembl_genes')['updated'])
Exemplo n.º 28
0
    def test_edit_comment(self):
        str_item = STRFactory()
        current_version = str_item.panel.version

        evaluation_url = reverse_lazy('panels:review_entity',
                                      kwargs={
                                          'pk': str_item.panel.panel.pk,
                                          'entity_type': 'str',
                                          'entity_name': str_item.name
                                      })

        comment = fake.sentence()

        gene_data = {
            "rating":
            Evaluation.RATINGS.AMBER,
            "current_diagnostic":
            True,
            "comments":
            comment,
            "publications":
            ";".join([fake.sentence(), fake.sentence()]),
            "phenotypes":
            ";".join([fake.sentence(),
                      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],
        }
        self.client.post(evaluation_url,
                         gene_data,
                         HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(
            pk=str_item.panel.panel.pk).active_panel.get_str(str_item.name)
        evaluation = gene.evaluation.get(user=self.gel_user)

        assert evaluation.comments.first().comment == comment

        get_comment_url = reverse_lazy('panels:edit_comment_by_user',
                                       kwargs={
                                           'pk':
                                           str_item.panel.panel.pk,
                                           'entity_type':
                                           'str',
                                           'entity_name':
                                           str_item.name,
                                           'comment_pk':
                                           evaluation.comments.first().pk
                                       })
        res = self.client.get(get_comment_url,
                              HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(res.status_code, 200)

        new_comment = fake.sentence()
        edit_comment_url = reverse_lazy('panels:submit_edit_comment_by_user',
                                        kwargs={
                                            'pk':
                                            str_item.panel.panel.pk,
                                            'entity_type':
                                            'str',
                                            'entity_name':
                                            str_item.name,
                                            'comment_pk':
                                            evaluation.comments.first().pk
                                        })
        res = self.client.post(edit_comment_url, {'comment': new_comment})
        assert res.status_code == 302
        assert evaluation.comments.first().comment == new_comment
        assert current_version == str_item.panel.panel.active_panel.version