Skip to content

Commit

Permalink
Merge pull request #2030 from AllenInstitute/bugfix/2030-analysisbrow…
Browse files Browse the repository at this point in the history
…ser-reusing-wrong-index-in-map

Fix analysis browser storing the wrong index
  • Loading branch information
t-b authored Mar 7, 2024
2 parents a0f016e + 23a4086 commit f26393d
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 72 deletions.
68 changes: 39 additions & 29 deletions Packages/MIES/MIES_AnalysisBrowser.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ End
static Function AB_AddMapEntry(baseFolder, discLocation)
string baseFolder, discLocation

variable index, fileID, nwbVersion, dim
variable nextFreeIndex, fileID, nwbVersion, dim, writeIndex
string dataFolder, fileType, relativePath, extension
WAVE/T map = GetAnalysisBrowserMap()

Expand All @@ -99,21 +99,22 @@ static Function AB_AddMapEntry(baseFolder, discLocation)
return -1
endif

index = GetNumberFromWaveNote(map, NOTE_INDEX)
nextFreeIndex = GetNumberFromWaveNote(map, NOTE_INDEX)
dim = FindDimLabel(map, COLS, "DiscLocation")
FindValue/TEXT=""/TXOP=4/RMD=[][dim] map
if(V_row < index)
index = V_row
FindValue/TEXT=""/TXOP=4/RMD=[0, nextFreeIndex - 1][dim] map
if(V_row >= 0)
writeIndex = V_row
else
EnsureLargeEnoughWave(map, indexShouldExist=index, dimension=ROWS)
writeIndex = nextFreeIndex
EnsureLargeEnoughWave(map, indexShouldExist=writeIndex, dimension=ROWS)
endif

// %DiscLocation = full path to file
map[index][%DiscLocation] = discLocation
map[writeIndex][%DiscLocation] = discLocation

// %FileName = filename + extension
relativePath = RemovePrefix(discLocation, start = baseFolder)
map[index][%FileName] = relativePath
map[writeIndex][%FileName] = relativePath

extension = "." + GetFileSuffix(discLocation)

Expand Down Expand Up @@ -141,19 +142,21 @@ static Function AB_AddMapEntry(baseFolder, discLocation)
default:
ASSERT(0, "invalid file type")
endswitch
map[index][%FileType] = fileType
map[writeIndex][%FileType] = fileType

DFREF dfrAB = GetAnalysisFolder()
DFREF dfr = dfrAB:$AB_GetUserData(AB_UDATA_WORKINGDF)
DFREF expFolder = UniqueDataFolder(dfr, RemoveEnding(relativePath, extension))
dataFolder = RemovePrefix(GetDataFolder(1, expFolder), start = GetDataFolder(1, dfrAB))
map[index][%DataFolder] = RemoveEnding(dataFolder, ":")
map[writeIndex][%DataFolder] = RemoveEnding(dataFolder, ":")
RefCounterDFIncrease(expFolder)

index += 1
SetNumberInWaveNote(map, NOTE_INDEX, index)
if(writeIndex == nextFreeIndex)
nextFreeIndex += 1
SetNumberInWaveNote(map, NOTE_INDEX, nextFreeIndex)
endif

return index - 1
return writeIndex
End

static Function AB_RemoveMapEntry(variable index)
Expand Down Expand Up @@ -2949,28 +2952,35 @@ Function AB_ButtonProc_AddFiles(ba) : ButtonControl
break
endif
WAVE/T selFiles = ListToTextWave(fileList, "\r")
Duplicate/FREE/T selFiles, newFiles

WAVE/T folderList = GetAnalysisBrowserGUIFolderList()
size = DimSize(selFiles, ROWS)
for(i = 0; i < size; i += 1)
FindValue/TEXT=selFiles[i]/TXOP=4 folderList
if(V_Value >= 0)
continue
endif
AB_AddElementToSourceList(selFiles[i])
newFiles[index] = selFiles[i]
index += 1
endfor
Redimension/N=(index) newFiles

AB_AddExperimentEntries(ba.win, newFiles)
AB_AddFiles(ba.win, selFiles)
break
endswitch

return 0
End

static Function AB_AddFiles(string win, WAVE/T selFiles)

variable i, index, size

Duplicate/FREE/T selFiles, newFiles

WAVE/T folderList = GetAnalysisBrowserGUIFolderList()
size = DimSize(selFiles, ROWS)
for(i = 0; i < size; i += 1)
FindValue/TEXT=selFiles[i]/TXOP=4 folderList
if(V_Value >= 0)
continue
endif
AB_AddElementToSourceList(selFiles[i])
newFiles[index] = selFiles[i]
index += 1
endfor
Redimension/N=(index) newFiles

AB_AddExperimentEntries(win, newFiles)
End

Function AB_AddElementToSourceList(string entry)

variable size
Expand Down
6 changes: 1 addition & 5 deletions Packages/MIES/MIES_Downsample.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,7 @@ Function DownsampleWindowHook(s)
KillOrMoveToTrash(wv=GetDownsampleListWave())
KillOrMoveToTrash(wv=GetDownsampleDataRefWave())
KillOrMoveToTrash(wv=GetDownsampleRateWave())

RecursiveRemoveEmptyDataFolder($dataPath)
if(DataFolderExists(dataPath))
printf "Could not remove all contents of %s\r", dataPath
endif
KillOrMoveToTrash(dfr=$dataPath)
break
endswitch

Expand Down
30 changes: 30 additions & 0 deletions Packages/MIES/MIES_GuiUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,36 @@ Function GetListBoxSelRow(win, ctrl)
return V_Value
End

/// @brief Set the listbox selection
///
/// @param win panel
/// @param ctrl control
/// @param val One of @ref ListBoxSelectionWaveFlags
/// @param row row index
/// @param col [optional, defaults to all columns] column index
Function SetListBoxSelection(string win, string ctrl, variable val, variable row, [variable col])

variable colStart, colEnd

if(ParamIsDefault(col))
colStart = 0
colEnd = inf
else
colStart = col
colEnd = col
endif

ControlInfo/W=$win $ctrl
ASSERT(V_flag == 11, "Not a listbox control")
WAVE/Z selWave = $GetValueFromRecMacro("selWave", S_recreation)
ASSERT(WaveExists(selWave), "Missing selection wave")

ASSERT(row < DimSize(selWave, ROWS), "Invalid row")
ASSERT(col < DimSize(selWave, COLS), "Invalid col")

selWave[row][colStart, colEnd][0][0] = val
End

/// @brief Check if the location `loc` is inside the rectangle `r`
Function IsInsideRect(loc, r)
STRUCT Point& loc
Expand Down
34 changes: 4 additions & 30 deletions Packages/MIES/MIES_Utilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ Function IsDataFolderEmpty(DFREF dfr)
) == 0
End

/// @brief Removes all empty datafolders in the passed datafolder reference
/// @brief Remove all empty datafolders in the passed datafolder reference recursively including sourceDFR
Function RemoveAllEmptyDataFolders(sourceDFR)
DFREF sourceDFR

Expand All @@ -991,39 +991,13 @@ Function RemoveAllEmptyDataFolders(sourceDFR)

numFolder = CountObjectsDFR(sourceDFR, COUNTOBJECTS_DATAFOLDER)

if(!numFolder)
return NaN
endif

for(i = numFolder - 1; i >= 0; i -= 1)
folder = GetDataFolder(1, sourceDFR) + GetIndexedObjNameDFR(sourceDFR, COUNTOBJECTS_DATAFOLDER, i)
RemoveEmptyDataFolder($folder)
RemoveAllEmptyDataFolders($folder)
endfor
end

/// @brief Recursively remove all folders from the datafolder path,
/// if and only if all are empty.
Function RecursiveRemoveEmptyDataFolder(dfr)
dfref dfr

variable numItems, i
string path, partialPath

if(!DataFolderExistsDFR(dfr))
return 0
endif

path = GetDataFolder(1, dfr)
path = RemoveEnding(path, ":")
numItems = ItemsInList(path, ":")
partialPath = path
for(i=numItems-1; i >= 1; i-=1)
if(!RemoveEmptyDataFolder($partialPath))
break
endif
partialPath = RemoveEnding(partialPath, ":" + StringFromList(i, path, ":"))
endfor
End
RemoveEmptyDataFolder(sourceDFR)
end

/// @name Debugger state constants for DisableDebugger and ResetDebuggerState
/// @{
Expand Down
7 changes: 4 additions & 3 deletions Packages/tests/Basic/UTF_Utils.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Function RemoveAllEmpty_init_IGNORE()
NewDataFolder/O root:removeMe:X7
Make/O root:removeMe:X7:data
NewDataFolder/O root:removeMe:X8
NewDataFolder/O root:removeMe:x8
NewDataFolder/O root:removeMe:X8:Y8
NewDataFolder/O root:removeMe:X8:Y8:Z8
End

Function RemoveAllEmpty_Works1()
Expand All @@ -73,7 +74,7 @@ Function RemoveAllEmpty_Works3()
NewDataFolder ttest
string folder = GetDataFolder(1) + "ttest"
RemoveAllEmptyDataFolders($folder)
CHECK(DataFolderExists(folder))
CHECK(!DataFolderExists(folder))
End

Function RemoveAllEmpty_Works4()
Expand All @@ -82,7 +83,7 @@ Function RemoveAllEmpty_Works4()

DFREF dfr = root:removeMe
RemoveAllEmptyDataFolders(dfr)
CHECK_EQUAL_VAR(CountObjectsDFR(dfr, 4), 4)
CHECK_EQUAL_VAR(CountObjectsDFR(dfr, COUNTOBJECTS_DATAFOLDER), 3)
End
/// @}

Expand Down
26 changes: 26 additions & 0 deletions Packages/tests/HistoricData/UTF_HistoricDashboard.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,29 @@ Function TestDashboardWithHistoricData([string str])
bsPanel = BSP_GetPanel(sbWin)
PGC_SetAndActivateControl(bsPanel, "check_BrowserSettings_DS", val = 1)
End

Function TestAnalysisBrowserAddingFiles()

string abWin, sweepBrowsers, fileToReadd
variable holeIndex

WAVE/T files = GetHistoricDataFiles()
files[] = "input:" + files[p]

[abWin, sweepBrowsers] = OpenAnalysisBrowser(files)

PGC_SetAndActivateControl(abWin, "button_collapse_all")

WAVE/T map = GetAnalysisBrowserMap()
CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS))

holeIndex = 1
fileToReadd = map[holeIndex]

SetListBoxSelection(abWin, "listbox_AB_Folders", LISTBOX_SELECTED, holeIndex)
PGC_SetAndActivateControl(abWin, "button_AB_Remove")
CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS))

MIES_AB#AB_AddFiles(abWin, {fileToReadd})
CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS))
End
10 changes: 5 additions & 5 deletions Packages/tests/HistoricData/UTF_HistoricData.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ End
Function/WAVE GetHistoricDataFiles()

Make/FREE/T files = {"C57BL6J-629713.05.01.02.pxp", \
"Chat-IRES-Cre-neo;Ai14-582723.15.10.01.pxp", \
"Pvalb-IRES-Cre;Ai14-646904.13.03.02.pxp", \
"Sst-IRES-Cre;Ai14-554002.08.06.02.pxp", \
"Sst-IRES-Cre;Th-P2A-FlpO;Ai65-561491.09.09.02.pxp", \
"epoch_clipping_2022_03_08_140256.pxp"}
"Chat-IRES-Cre-neo;Ai14-582723.15.10.01.pxp", \
"Pvalb-IRES-Cre;Ai14-646904.13.03.02.pxp", \
"Sst-IRES-Cre;Ai14-554002.08.06.02.pxp", \
"Sst-IRES-Cre;Th-P2A-FlpO;Ai65-561491.09.09.02.pxp", \
"epoch_clipping_2022_03_08_140256.pxp"}

DownloadFilesIfRequired(files)
SetLabelsForDGWave(files)
Expand Down

0 comments on commit f26393d

Please sign in to comment.