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 ROI deletion feature #1880

Merged
merged 3 commits into from
Sep 4, 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
28 changes: 4 additions & 24 deletions js/roi/ROIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ class ROIManager {
return this.roiSets.find(roiSet => true === roiSet.isUserDefined)
}

deleteUserDefinedROISet(){
this.roiSets = this.roiSets.filter(roiSet => roiSet.isUserDefined !== true);
}

initializeUserDefinedROISet() {

const config =
Expand All @@ -289,15 +293,8 @@ class ROIManager {
}

async deleteRegionWithKey(regionKey, columnContainer) {

columnContainer.querySelectorAll(createSelector(regionKey)).forEach(node => node.remove())

const {feature, set} = await this.findRegionWithKey(regionKey)

if (set) {
set.removeFeature(feature)
}

const records = await this.getTableRecords()

if (0 === records.length) {
Expand All @@ -307,23 +304,6 @@ class ROIManager {

}

async findRegionWithKey(regionKey) {

const {chr, start, end} = parseRegionKey(regionKey)

for (let set of this.roiSets) {
const features = await set.getFeatures(chr, start, end)

for (let feature of features) {
if (feature.chr === chr && feature.start >= start && feature.end <= end) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this line was causing the issue as it was not an exact match for start and end but we don't need this method now.

return {feature, set}
}
}
}

return {feature: undefined, set: undefined}
}

toJSON() {
return this.roiSets.map(roiSet => roiSet.toJSON())
}
Expand Down
13 changes: 10 additions & 3 deletions js/roi/ROIMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,16 @@ class ROIMenu {
'<hr/>',
{
label: 'Delete',
click: () => {
this.browser.roiManager.deleteRegionWithKey(regionElement.dataset.region, this.browser.columnContainer)
this.browser.roiManager.repaintTable()
click: async () => {
roiSet.removeFeature(feature)
const userDefinedFeatures = await roiSet.getAllFeatures()

// Delete user defined ROI Set if it is empty
if (Object.keys(userDefinedFeatures).length === 0) {
roiManager.deleteUserDefinedROISet()
}
roiManager.deleteRegionWithKey(regionElement.dataset.region, columnContainer)
roiManager.repaintTable()
}
}
)
Expand Down
4 changes: 4 additions & 0 deletions js/roi/ROISet.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ class DynamicFeatureSource {
if (this.featureMap[chr]) {
const match = `${chr}-${start}-${end}`
this.featureMap[chr] = this.featureMap[chr].filter(feature => match !== `${feature.chr}-${feature.start}-${feature.end}`)
// Check if featureMap for a specific chromosome is empty now and delete it if yes
if (this.featureMap[chr].length === 0) {
delete this.featureMap[chr];
}
}
}
}
Expand Down
Loading