Skip to content

Commit 9ea1e47

Browse files
authored
Merge pull request #401 from lenatr99/gene_annot_fix
[FIX] LoadData - Manually add gene and cell annotations, correct Source name
2 parents 43f70d9 + 3d7c04c commit 9ea1e47

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

orangecontrib/single_cell/widgets/load_data.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,18 @@ def leading_cols(self, value):
488488

489489
def _set_annotation_files(self):
490490
dir_name, _ = os.path.split(self._file_name)
491-
genes_path = os.path.join(dir_name, "genes.tsv")
492-
if os.path.isfile(genes_path):
493-
self.col_annotation_file = RecentPath.create(genes_path, [])
494-
barcodes_path = os.path.join(dir_name, "barcodes.tsv")
491+
genes_paths = ['genes.tsv', 'features.tsv', 'genes.tsv.gz', 'features.tsv.gz']
492+
for genes_path in genes_paths:
493+
genes_path = os.path.join(dir_name, genes_path)
494+
if os.path.isfile(genes_path):
495+
self.col_annotation_file = RecentPath.create(genes_path, [])
496+
break
497+
barcodes_paths = ['barcodes.tsv', 'barcodes.tsv.gz']
498+
for barcodes_path in barcodes_paths:
499+
barcodes_path = os.path.join(dir_name, barcodes_path)
500+
if os.path.isfile(barcodes_path):
501+
self.row_annotation_file = RecentPath.create(barcodes_path, [])
502+
break
495503
if os.path.isfile(barcodes_path):
496504
self.row_annotation_file = RecentPath.create(barcodes_path, [])
497505

@@ -756,13 +764,21 @@ def key(var):
756764
metas=sorted(metas, key=key))
757765
concat_data_t = concat_data.transform(domain)
758766
data_t = data.transform(domain)
759-
source_var.values + (source_name, )
767+
768+
new_values = source_var.values + (source_name,)
769+
new_source_var = DiscreteVariable(source_var.name, values=new_values)
770+
new_metas = tuple(var if var.name != source_var.name else new_source_var for var in domain.metas)
771+
new_domain = Domain(domain.attributes, metas=new_metas)
772+
concat_data_t = concat_data_t.transform(new_domain)
773+
data_t = data_t.transform(new_domain)
774+
source_var_index = new_source_var.values.index(source_name)
760775
# metas can be unlocked, source_var added to metas by append_source_name
761776
with data_t.unlocked(data_t.metas):
762-
data_t[:, source_var] = np.full(
763-
(len(data), 1), len(source_var.values) - 1, dtype=object
777+
data_t[:, new_source_var] = np.full(
778+
(len(data_t), 1), source_var_index, dtype=object
764779
)
765780
concat_data = Table.concatenate((concat_data_t, data_t), axis=0)
781+
source_var = new_source_var # Update source_var for the next iteration
766782
return concat_data
767783

768784
@staticmethod

orangecontrib/single_cell/widgets/owloaddata.py

+2
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ def browse_row_annotations(self):
613613
pathitem = RecentPath.create(filename, [])
614614
index = insert_recent_path(m, pathitem)
615615
self.row_annotations_combo.setCurrentIndex(index)
616+
self._row_annotations_combo_changed()
616617
self._invalidate()
617618

618619
@Slot()
@@ -632,6 +633,7 @@ def browse_col_annotations(self):
632633
pathitem = RecentPath.create(filename, [])
633634
index = insert_recent_path(m, pathitem)
634635
self.col_annotations_combo.setCurrentIndex(index)
636+
self._col_annotations_combo_changed()
635637
self._invalidate()
636638

637639
def _invalidate(self):

0 commit comments

Comments
 (0)