barcodeBuildFunc modifies external variables
guoyang-github opened this issue · 1 comments
Dear Starfish developers,
Firstly, thank you for creating such a useful tool for decode analysis. I have been using the barcodeBuildFunc function and noticed a piece of code related to the modification of external variables within the function.
def barcodeBuildFunc(allNeighbors: list, currentRound: int, roundOmitNum: int, roundNum: int) -> list:
allSpotCodes = []
for neighbors in allNeighbors:
neighborLists = [neighbors[rnd] for rnd in range(roundNum)]
if roundOmitNum > 0:
[neighbors[rnd].append(0) for rnd in range(roundNum)]
codes = list(product(*neighborLists))
In the current implementation of barcodeBuildFunc, the function modifies the neighbors object, which refers to an external variable, and in turn affects upstream variables neighborLists. I'm not sure whether it will lead to unintended side effects. If I change the code to the following form, I wonder if it makes sense?
def barcodeBuildFunc_revised(allNeighbors: list, currentRound: int, roundOmitNum: int, roundNum: int) -> list:
allSpotCodes = []
for neighbors in allNeighbors:
if roundOmitNum > 0:
neighbors = [neighbors[rnd] + [0] for rnd in range(roundNum)]
neighborLists = [neighbors[rnd] for rnd in range(roundNum)]
codes = list(product(*neighborLists))
Thanks for your help.
The permalink to the code:
https://github.com/spacetx/starfish/blob/master/starfish/core/spots/DecodeSpots/check_all_funcs.py