Skip to content

Commit

Permalink
Merge pull request #401 from lenatr99/gene_annot_fix
Browse files Browse the repository at this point in the history
[FIX] LoadData - Manually add gene and cell annotations, correct Source name
  • Loading branch information
lenatr99 authored May 29, 2024
2 parents 43f70d9 + 3d7c04c commit 9ea1e47
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 23 additions & 7 deletions orangecontrib/single_cell/widgets/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,18 @@ def leading_cols(self, value):

def _set_annotation_files(self):
dir_name, _ = os.path.split(self._file_name)
genes_path = os.path.join(dir_name, "genes.tsv")
if os.path.isfile(genes_path):
self.col_annotation_file = RecentPath.create(genes_path, [])
barcodes_path = os.path.join(dir_name, "barcodes.tsv")
genes_paths = ['genes.tsv', 'features.tsv', 'genes.tsv.gz', 'features.tsv.gz']
for genes_path in genes_paths:
genes_path = os.path.join(dir_name, genes_path)
if os.path.isfile(genes_path):
self.col_annotation_file = RecentPath.create(genes_path, [])
break
barcodes_paths = ['barcodes.tsv', 'barcodes.tsv.gz']
for barcodes_path in barcodes_paths:
barcodes_path = os.path.join(dir_name, barcodes_path)
if os.path.isfile(barcodes_path):
self.row_annotation_file = RecentPath.create(barcodes_path, [])
break
if os.path.isfile(barcodes_path):
self.row_annotation_file = RecentPath.create(barcodes_path, [])

Expand Down Expand Up @@ -756,13 +764,21 @@ def key(var):
metas=sorted(metas, key=key))
concat_data_t = concat_data.transform(domain)
data_t = data.transform(domain)
source_var.values + (source_name, )

new_values = source_var.values + (source_name,)
new_source_var = DiscreteVariable(source_var.name, values=new_values)
new_metas = tuple(var if var.name != source_var.name else new_source_var for var in domain.metas)
new_domain = Domain(domain.attributes, metas=new_metas)
concat_data_t = concat_data_t.transform(new_domain)
data_t = data_t.transform(new_domain)
source_var_index = new_source_var.values.index(source_name)
# metas can be unlocked, source_var added to metas by append_source_name
with data_t.unlocked(data_t.metas):
data_t[:, source_var] = np.full(
(len(data), 1), len(source_var.values) - 1, dtype=object
data_t[:, new_source_var] = np.full(
(len(data_t), 1), source_var_index, dtype=object
)
concat_data = Table.concatenate((concat_data_t, data_t), axis=0)
source_var = new_source_var # Update source_var for the next iteration
return concat_data

@staticmethod
Expand Down
2 changes: 2 additions & 0 deletions orangecontrib/single_cell/widgets/owloaddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ def browse_row_annotations(self):
pathitem = RecentPath.create(filename, [])
index = insert_recent_path(m, pathitem)
self.row_annotations_combo.setCurrentIndex(index)
self._row_annotations_combo_changed()
self._invalidate()

@Slot()
Expand All @@ -632,6 +633,7 @@ def browse_col_annotations(self):
pathitem = RecentPath.create(filename, [])
index = insert_recent_path(m, pathitem)
self.col_annotations_combo.setCurrentIndex(index)
self._col_annotations_combo_changed()
self._invalidate()

def _invalidate(self):
Expand Down

0 comments on commit 9ea1e47

Please sign in to comment.