802ca99f5f06437c32db764bc8e01786ed395c21
braney
  Tue Apr 7 14:05:35 2026 -0700
Fix mergeSpannedItems not working with quickLift

For quickLifted tracks, bb->start/bb->end are in the source assembly
coordinates while winStart/winEnd are in the target assembly, so the
span check never matched. Use lf->start/lf->end (lifted coordinates)
when quickLiftFile is set. Also use cloneBed(bedCopy) for building the
merged item instead of re-parsing from source-assembly bedRow, refs #36048

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

diff --git src/hg/hgTracks/bigBedTrack.c src/hg/hgTracks/bigBedTrack.c
index ef787dc982f..8cf163a7f4b 100644
--- src/hg/hgTracks/bigBedTrack.c
+++ src/hg/hgTracks/bigBedTrack.c
@@ -817,36 +817,48 @@
             else
                 {
                 bed = bedLoadN(bedRow, fieldCount == 7 ? 6 : fieldCount);
                 bedCopy = cloneBed(bed);
                 lf = bedMungToLinkedFeatures(&bed, tdb, fieldCount,
                     scoreMin, scoreMax, useItemRgb);
                 }
             }
 
         if (lf && highlights)
             addHighlightToLinkedFeature(lf, highlights, bbi, bedRow, track->tdb);
 
         if (lf && squishFieldIdx)
             lf->squishyPackVal = atof(restField(bb, squishFieldIdx));
 
-        if (track->visibility != tvDense && lf && doWindowSizeFilter && bb->start < winStart && bb->end > winEnd)
+        if (track->visibility != tvDense && lf && doWindowSizeFilter
+            && (quickLiftFile ? lf->start : bb->start) < winStart
+            && (quickLiftFile ? lf->end : bb->end) > winEnd)
             {
             mergeCount++;
+            struct linkedFeatures *tmp;
+            if (quickLiftFile)
+                {
+                struct bed *mergeBed = cloneBed(bedCopy);
+                tmp = bedMungToLinkedFeatures(&mergeBed, tdb, fieldCount,
+                    scoreMin, scoreMax, useItemRgb);
+                }
+            else
+                {
                 struct bed *bed = bedLoadN(bedRow, fieldCount);
-            struct linkedFeatures *tmp = bedMungToLinkedFeatures(&bed, tdb, fieldCount,
+                tmp = bedMungToLinkedFeatures(&bed, tdb, fieldCount,
                     scoreMin, scoreMax, useItemRgb);
+                }
             if (spannedLf)
                 {
                 if (tmp->start < spannedLf->start)
                     spannedLf->start = tmp->start;
                 if (tmp->end > spannedLf->end)
                     spannedLf->end = tmp->end;
                 if (fieldCount > 9) // average the colors in the merged item
                     {
                     // Not sure how averaging alphas in the merged item would work; probably better
                     // to ignore it.
                     struct rgbColor itemColor = colorIxToRgb(lf->filterColor);
                     struct rgbColor currColor = colorIxToRgb(spannedLf->filterColor);
                     int r = currColor.r + round((itemColor.r - currColor.r) / mergeCount);
                     int g = currColor.g + round((itemColor.g - currColor.g) / mergeCount);
                     int b = currColor.b + round((itemColor.b - currColor.b) / mergeCount);