Skip to content

Commit

Permalink
Fix ROI deletion feature (#1880)
Browse files Browse the repository at this point in the history
* Fixed deletion of ROI

* Added deletion of empty userDefinedROISet
  • Loading branch information
milandomazet authored Sep 4, 2024
1 parent 64daf5a commit 87b3652
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
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) {
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

0 comments on commit 87b3652

Please sign in to comment.