dasmoth / dalliance

Interactive web-based genome browser.
http://www.biodalliance.org/
BSD 2-Clause "Simplified" License
226 stars 68 forks source link

Single Base BED Box #240

Open denisemauldin opened 5 years ago

denisemauldin commented 5 years ago

Hi there,

I'm attempting to highlight a single basepair in the browser. My BED row is: "chr4 4175043 4175058 spacer 999 - 4175051 4175052 255,0,0 1 15 0"

The top image is what it displays. The bottom image is what I want it to display.
biodalliance_single_basepair

If I change the BED row to be this: "chr4 4175043 4175058 spacer 999 - 4175051 4175051 255,0,0 1 15 0" Then it displays no red.

If I change the BED row to be this: "chr4 4175043 4175058 spacer 999 - 4175050 4175051 255,0,0 1 15 0" Then it displays this: biodalliance_left

How do I get it to just color one base pair (4175051) red?

denisemauldin commented 5 years ago

As far as I can tell, I need to add a condition to the code to skip the thickStart -3 and thickEnd +3 codingRegion calculation.

I added this to make BedParseSession.prototype.parse draw 1 base pair:

            } else if (thickEnd == thickStart) {
                var codingRegion = f.orientation == '+' ? new Range(thickStart, thickEnd) : new Range(thickStart, thickEnd);
                var tl = intersection(spans, codingRegion);
                if (tl) {
                    f.type = 'translation';
                    var tlList = tl.ranges();
                    var readingFrame = 0;
                    for (var s = 0; s < tlList.length; ++s) {
                        // Record reading frame for every exon
                        var index = s;
                        if (f.orientation == '-') index = tlList.length - s - 1;
                        var ts = tlList[index];
                        var bf = shallowCopy(f);
                        bf.min = ts.min();
                        bf.max = ts.max();
                        f.readframe = readingFrame;
                        var length = ts.max() - ts.min();
                        readingFrame = (readingFrame + length) % 3;
                        this.sink(bf);
                    }
                }
            }

Maybe I should be using some parser other than the BedParseSession.prototype.parse? Would it be useful to contribute this code back?

dasmoth commented 5 years ago

Thanks for looking into this. Yes, you're looking in the right place. The +/-3 thing is because this style of BED is usually being used to represent protein-coding regions. I guess you're using it for something else (would be quite curious to know what, if it's not sensitive information).

I suspect what's really needed here is a flag here to optionally suppress the +/-3 behaviour. That ends up being slightly annoying in that there's not currently a way to pass per-track config flags to parsers. However, it wouldn't be too hard to pass the track config in as an extra parameter to Parser.createSession...