def test_common_taxonomy(self):
        self.assertGreater(len(taxonomy.common_taxids()), 0)

        self.assertEqual(taxonomy.name(self.human), 'H**o sapiens')
        self.assertEqual(taxonomy.name(self.dicty), 'Dictyostelium discoideum')

        self.assertEqual(taxonomy.species_name_to_taxid('H**o sapiens'),
                         self.human)
        self.assertEqual(
            taxonomy.species_name_to_taxid('Dictyostelium discoideum'),
            self.dicty)

        self.assertGreater(len(taxonomy.shortname(self.human)), 0)
        self.assertGreater(len(taxonomy.shortname(self.dicty)), 0)
    def test_uncommon_taxonomy(self):
        self.assertTrue(self.dog not in taxonomy.common_taxids())
        self.assertEqual(taxonomy.name(self.dog), 'Canis lupus familiaris')

        # not supported yet.
        self.assertIsNone(
            taxonomy.species_name_to_taxid('Canis lupus familiaris'))
        self.assertFalse(len(taxonomy.shortname(self.dog)))
    def create_model(self):
        allkeys = set(self.allinfo_local)

        if self.allinfo_remote is not None:
            allkeys = allkeys | set(self.allinfo_remote)

        allkeys = sorted(allkeys)

        model = QStandardItemModel(self)
        model.setHorizontalHeaderLabels(self._header_labels)

        current_index = -1
        for i, file_path in enumerate(allkeys):
            data_info = self._parse_info(file_path)
            row = []

            for info_tag, header_setting in self.HEADER_SCHEMA:
                item = QStandardItem()

                try:
                    data = data_info.__getattribute__(info_tag)
                except AttributeError:
                    # unknown tag in JSON
                    data = ''

                # first column indicating cached data sets
                if info_tag == 'islocal':
                    item.setData(' ' if data else '', Qt.DisplayRole)
                    item.setData(data_info, Qt.UserRole)

                else:
                    # parse taxid to common name
                    if info_tag == 'taxid' and data in common_taxids():
                        data = shortname(data)[0].title()

                    if info_tag == 'tags':
                        data = ', '.join(data) if data else ''

                    item.setData(data, Qt.DisplayRole)

                # set icon to Target column
                if info_tag == 'target' and data:
                    item.setIcon(
                        Orange.widgets.data.owdatasets.variable_icon(data))

                row.append(item)
            model.appendRow(row)

            if os.path.join(*file_path) == self.selected_id:
                current_index = i

        return model, current_index
Example #4
0
def register_serverfiles(genesets):
    """ Registers using the common hierarchy and organism. """
    org = genesets.common_org()
    hierarchy = genesets.common_hierarchy()
    fn = filename(hierarchy, org)

    file_path = os.path.join(DOMAIN_PATH, fn)

    if org is not None:
        taxname = taxonomy.name(org)
        title = "Gene sets: " + ", ".join(hierarchy) + (
            (" (" + taxname + ")") if org is not None else "")

        tags = list(hierarchy) + ["gene sets"] + (
            [taxname] if org is not None else []) + taxonomy.shortname(org)
        genesets.to_gmt_file_format(file_path)
        create_info_file(file_path, title=title, tags=tags)
Example #5
0
def prepare_gene_sets_serverfiles():
    Path('serverfiles/gene_sets/').mkdir(parents=True, exist_ok=True)

    for file in list_files('data/gene_sets/'):
        source_path = str(file.absolute())
        dest_path = f'serverfiles/gene_sets/{file.name}'
        shutil.copy2(source_path, dest_path)

        hierarchy, tax_id = filename_parse(file.name)
        title = f"Gene sets: {', '.join(hierarchy)} ({common_taxid_to_name(tax_id)})"
        tags = list(hierarchy) + ['gene sets',
                                  common_taxid_to_name(tax_id)
                                  ] + shortname(tax_id)

        server_file = ServerFile(domain='gene_sets',
                                 file_path=dest_path,
                                 title=title,
                                 description='',
                                 tags=tags)

        server_file.to_server_format()