Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] LoadData - Bugs with gene and cell annotations #403

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Widgets
widgets/score_genes
widgets/score_cells
widgets/dot_matrix
widgets/spatial_autocorrelation
7 changes: 7 additions & 0 deletions doc/widgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
"icon": "../orangecontrib/single_cell/widgets/icons/DotMatrix.svg",
"background": "light-blue",
"keywords": []
},
{
"text": "Spatial Autocorrelation Scorer",
"doc": "widgets/spatial_autocorrelation.md",
"icon": "../orangecontrib/single_cell/widgets/icons/SpatialAutocorrelation.svg",
"background": "light-blue",
"keywords": []
}
]
]
Expand Down
32 changes: 23 additions & 9 deletions orangecontrib/single_cell/widgets/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +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")
if os.path.isfile(barcodes_path):
self.row_annotation_file = RecentPath.create(barcodes_path, [])
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

def _set_enable_annotations(self):
# 10x gene-barcode matrix
Expand Down Expand Up @@ -756,13 +762,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
Loading