Пример #1
0
def test_advanced_get_one_variant(conn):
    """Test getting variant from variant_id

    .. note:: annotations and samples which are optional ARE tested here
    """
    for variant_id, expected_variant in enumerate(VARIANTS, 1):
        found_variant = sql.get_one_variant(conn,
                                            variant_id,
                                            with_annotations=True,
                                            with_samples=True)

        for extra_field in ("annotations", "samples"):

            assert isinstance(found_variant[extra_field],
                              list), "Type not expected"

            for item in found_variant[extra_field]:
                # Remove variant_id and sample_id from sample/annotation before test
                if "variant_id" in item:
                    del item["variant_id"]

                if "sample_id" in item:
                    del item["sample_id"]

            if extra_field in found_variant and extra_field in expected_variant:
                assert found_variant[extra_field] == expected_variant[
                    extra_field]
Пример #2
0
    def populate(self):
        """Show the current variant attributes on the TreeWidget

        .. note:: RichText in Markdown is supported starting PySide 5.14
        """
        if not self.current_variant or "id" not in self.current_variant:
            return

        variant_id = self.current_variant["id"]

        # Populate variant
        data = dict(
            [
                (k, v)
                for k, v in sql.get_one_variant(self.conn, variant_id).items()
                if k not in ("variant_id", "sample_id", "annotations", "samples")
            ]
        )
        self.variant_view.set_dict(data)

        self.edit_panel.set_data(data)

        title = "{chr}:{pos} {ref}>{alt}".format(**data)
        # self.parent().setWindowTitle(title)

        # Populate annotations
        self.transcript_combo.blockSignals(True)
        self.transcript_combo.clear()

        for annotation in sql.get_annotations(self.conn, variant_id):
            if "transcript" in annotation:
                self.transcript_combo.addItem(annotation["transcript"], annotation)
        self.on_transcript_changed()
        self.transcript_combo.blockSignals(False)

        # Populate samples
        self.sample_combo.blockSignals(True)
        self.sample_combo.clear()
        for sample in sql.get_samples(self.conn):
            self.sample_combo.addItem(sample["name"], sample["id"])
        self.on_sample_changed()
        self.sample_combo.blockSignals(False)

        # Populate genotypes for samples
        self.genotype_view.clear()
        query = f"""SELECT samples.name, sv.gt FROM samples 
                 LEFT JOIN sample_has_variant sv ON samples.id = sv.sample_id 
                 AND sv.variant_id = {variant_id}"""

        for sample_name, genotype in self.conn.execute(query):
            item = QListWidgetItem()
            icon = self.genotype_icons.get(genotype, self.genotype_icons[-1])

            item.setText(sample_name)
            item.setIcon(icon)
            item.setToolTip(cm.GENOTYPE_DESC.get(genotype, -1))

            self.genotype_view.addItem(item)
Пример #3
0
def test_update_variant(conn):
    """Test update procedure of a variant in DB (modify some of its field values)

    .. note:: exception si pas id, ajout comment
    """
    # Update the first variant data
    updated = {"id": 1, "ref": "A", "chr": "chrX"}
    sql.update_variant(conn, updated)

    inserted = sql.get_one_variant(conn, 1)

    assert inserted["ref"] == updated["ref"]
    assert inserted["chr"] == updated["chr"]
Пример #4
0
def test_get_one_variant(conn):
    """Test getting variant from variant_id

    .. note:: annotations and samples which are optional are not tested here
        => see :meth:`test_advanced_get_one_variant`
    """
    for variant_id, expected_variant in enumerate(VARIANTS, 1):
        found_variant = sql.get_one_variant(conn, variant_id)

        print("found variant", found_variant)
        assert found_variant["id"] == variant_id

        for k, v in expected_variant.items():
            if k not in ("annotations", "samples"):
                assert found_variant[k] == expected_variant[k]
Пример #5
0
    def populate(self):
        """Show the current variant attributes on the TreeWidget

        .. note:: RichText in Markdown is supported starting PySide 5.14
        """
        if not self.current_variant or "id" not in self.current_variant:
            return

        variant_id = self.current_variant["id"]

        # Populate variant
        self.populate_tree_widget(self.variant_view,
                                  sql.get_one_variant(self.conn, variant_id))

        # Populate annotations
        self.transcript_combo.blockSignals(True)
        self.transcript_combo.clear()
        for annotation in sql.get_annotations(self.conn, variant_id):
            if "transcript" in annotation:
                self.transcript_combo.addItem(annotation["transcript"],
                                              annotation)
        self.on_transcript_changed()
        self.transcript_combo.blockSignals(False)

        # Populate samples
        self.sample_combo.blockSignals(True)
        self.sample_combo.clear()
        for sample in sql.get_samples(self.conn):
            self.sample_combo.addItem(sample["name"], sample["id"])
        self.on_sample_changed()
        self.sample_combo.blockSignals(False)

        # Populate genotypes for samples
        self.genotype_view.clear()
        query = f"""SELECT samples.name, sv.gt FROM samples 
                 LEFT JOIN sample_has_variant sv ON samples.id = sv.sample_id 
                 AND sv.variant_id = {variant_id}"""

        for sample_name, genotype in self.conn.execute(query):
            item = QListWidgetItem()
            icon = self.genotype_icons.get(genotype, self.genotype_icons[-1])

            item.setText(sample_name)
            item.setIcon(icon)
            item.setToolTip(cm.GENOTYPE_DESC.get(genotype, -1))

            self.genotype_view.addItem(item)
Пример #6
0
    #     if "variant_view" in self.mainwindow.plugins:
    #         main_view = self.mainwindow.plugins["variant_view"]
    #         print(main_view)

    # sql.update_variant(self.conn, updated)

    # def show_menu(self, pos: QPoint):
    #     """Show context menu associated to the current variant"""
    #     if not self.current_variant:
    #         return
    #     self.context_menu.popup(self.current_variant, self.view.mapToGlobal(pos))


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)

    conn = get_sql_connection("/home/schutz/Dev/cutevariant/examples/test.db")

    w = VariantInfoWidget()
    w.conn = conn

    variant = sql.get_one_variant(conn, 1)

    w.current_variant = variant

    w.show()

    app.exec_()