Skip to content

barcodeBuildFunc modifies external variables #2007

Description

@guoyang-github

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue with an existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions