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

TypeError: this.ranges.map is not a function #59

Closed
guillemsegura opened this issue Feb 18, 2024 · 6 comments · Fixed by #61
Closed

TypeError: this.ranges.map is not a function #59

guillemsegura opened this issue Feb 18, 2024 · 6 comments · Fixed by #61

Comments

@guillemsegura
Copy link

Hi,

I'm loading a BigWig file and when calling this method as such:

bbi.getFeatures('chr7', 43110697, 43295697, {scale: 0.25, signal: {aborted: false, reason: undefined, onabort: null}})

It throws the following error:

Unhandled Runtime Error
TypeError: this.ranges.map is not a function

Call Stack
Range.getRanges
node_modules/@gmod/bbi/esm/range.js (40:0)
Range.union
node_modules/@gmod/bbi/esm/range.js (46:0)
cirFobRecur
node_modules/@gmod/bbi/esm/block-view.js (215:0)
cirFobRecur2
node_modules/@gmod/bbi/esm/block-view.js (175:0)
cirFobStartFetch
node_modules/@gmod/bbi/esm/block-view.js (195:0)

I believe it's because the union method creates a new Range with an array as only parameter:

[
    {
        "ranges": [
            {
                "min": 44784262,
                "max": 44792458
            }
        ]
    },
    {
        "ranges": [
            {
                "min": 44808850,
                "max": 44817046
            }
        ]
    }
]

And then in the constructor 0 in arg1 is true and an object is created instead of an array:

{
    "0": {
        "ranges": [
            {
                "min": 44784262,
                "max": 44792458
            }
        ]
    },
    "1": {
        "ranges": [
            {
                "min": 44808850,
                "max": 44817046
            }
        ]
    }
}

Finally when getRanges is called, it tries to call map on an object unsuccessfully.

I'll keep investigating.

Please let me know if you need more information to reproduce this issue.

@cmdcolin
Copy link
Collaborator

if you are able to supply the file you are testing on it may help. i can't reproduce this on my sample file, but don't doubt something could be wrong

the ranges code is definitely one of the more legacy parts of the codebase, i didn't try to refactor it at all when refactoring this module out of our jbrowse 1 codebase so would be happy to review/modernize it at some point

@cmdcolin
Copy link
Collaborator

any update? having the file may be easiest if you can send it, feel free to email at colin.diesh@gmail.com

@guillemsegura
Copy link
Author

Hi Colin,

Apologies for the delay. We were trying to figure out what was causing the original issue. We found that the files that have the chromosomes sorted lexicographically (i.e., chr1, chr10, chr11) don't have the issue, whereas the ones that have the chromosomes sorted by number (i.e., chr1, chr2, chr3) will show the error.

The ones with the error will have multiple values in recurOffsets in block-view.js and will go into the following code:

if (recurOffsets.length > 0) {
      cirFobRecur(recurOffsets, level + 1);
}

and inside the method cirFobRecur, it will reach the union method that's causing the error:

spans = spans.union(blockSpan);

example_bigwig_sorted_without_error_small.bw.zip
example_bigwig_unsorted_with_error_small.bw.zip

@cmdcolin
Copy link
Collaborator

cmdcolin commented Mar 5, 2024

thanks for the examples! now that you mention the sorting, I remember that another user ran into this same issue here GMOD/jbrowse-components#4168

@cmdcolin
Copy link
Collaborator

cmdcolin commented Mar 5, 2024

I published a new version (4.0.4) that appeared to fix the usage for the example file you added. The ranges code was simplified so that it should be less bug prone now. Let me know if that works :)

@guillemsegura
Copy link
Author

Hi Colin,

That works! Thanks for the quick response and fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants