Skip to content

Commit

Permalink
Expanded insertion issue - collapsing seemed to shift view, due to at…
Browse files Browse the repository at this point in the history
…tempt o center the collapsed insertion. This is visually disturbing.
  • Loading branch information
jrobinso committed Jul 26, 2024
1 parent 0f0b4fb commit a4cd2d5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 121 deletions.
98 changes: 0 additions & 98 deletions src/main/java/org/broad/igv/sam/AlignmentRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1083,104 +1083,6 @@ private void drawLargeIndelLabel(Graphics2D g, boolean isInsertion, String label
}
}

public void renderExpandedInsertion(InsertionMarker i,
List<Alignment> alignments,
RenderContext context,
Rectangle rect,
boolean leaveMargin) {
double origin = context.getOrigin();
double locScale = context.getScale();
if ((alignments != null) && (alignments.size() > 0)) {

Graphics2D g = context.getGraphics2D("INSERTIONS");
double dX = 1 / context.getScale();
int fontSize = (int) Math.min(dX, 12);
if (fontSize >= 8) {
Font f = FontManager.getFont(Font.BOLD, fontSize);
g.setFont(f);
}

for (Alignment alignment : alignments) {
if (alignment.getEnd() < i.position) continue;
if (alignment.getStart() > i.position) break;
AlignmentBlock insertion = alignment.getInsertionAt(i.position);
if (insertion != null) {

// Compute the start and dend of the alignment in pixels
double pixelStart = (insertion.getStart() - origin) / locScale;
double pixelEnd = (insertion.getEnd() - origin) / locScale;
int x = (int) pixelStart;

// If any any part of the feature fits in the track rectangle draw it
if (pixelEnd < rect.x || pixelStart > rect.getMaxX()) {
continue;
}

int bpWidth = insertion.getBasesLength();
double pxWidthExact = ((double) bpWidth) / locScale;
int h = (int) Math.max(1, rect.getHeight() - 2);
int y = (int) (rect.getY() + (rect.getHeight() - h) / 2) - 1;

if (!insertion.hasBases()) {
g.setColor(purple);
g.fillRect(x, y, (int) pxWidthExact, h);

} else {
drawExpandedInsertionBases(x, context, rect, insertion, leaveMargin);
}
}
}
}
}


private void drawExpandedInsertionBases(int pixelPosition,
RenderContext context,
Rectangle rect,
AlignmentBlock block,
boolean leaveMargin) {
Graphics2D g = context.getGraphics2D("INSERTIONS");
ByteSubarray bases = block.getBases();
int padding = block.getPadding();

double locScale = context.getScale();
double origin = context.getOrigin();

// Compute bounds
int pY = (int) rect.getY();
int dY = (int) rect.getHeight();
int dX = (int) Math.max(1, (1.0 / locScale));

final int size = bases.length + padding;
for (int p = 0; p < size; p++) {

char c = p < padding ? '-' : (char) bases.getByte(p - padding);

Color color = SequenceRenderer.nucleotideColors.get(c);
if (color == null) {
color = Color.black;
}

// If there is room for text draw the character, otherwise
// just draw a rectangle to represent the
int pX = (int) (pixelPosition + (p / locScale));

// Don't draw out of clipping rect
if (pX > rect.getMaxX()) {
break;
} else if (pX + dX < rect.getX()) {
continue;
}
BaseRenderer.drawBase(g, color, c, pX, pY, dX, dY - (leaveMargin ? 2 : 0), false, null);
}

int leftX = pixelPosition + context.translateX;
int rightX = leftX + rect.width;
block.setPixelRange(leftX, rightX);

}


private Color getAlignmentColor(Alignment alignment, AlignmentTrack track) {

// Set color used to draw the feature. Highlight features that intersect the
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/broad/igv/sam/BaseRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static void drawExpandedInsertions(InsertionMarker insertionMarker,
if (alignment.getStart() > insertionMarker.position) break;

AlignmentBlock insertion = alignment.getInsertionAt(insertionMarker.position);
if (insertion != null && insertion.hasBases()) {
if (insertion != null && insertion.getBasesLength() > 0) {

double origin = context.getOrigin();
double locScale = context.getScale();
Expand All @@ -104,8 +104,7 @@ public static void drawExpandedInsertions(InsertionMarker insertionMarker,

ByteSubarray bases = insertion.getBases();
int padding = insertion.getPadding();

final int size = bases.length + padding;
final int size = insertion.getBasesLength() + padding;
for (int p = 0; p < size; p++) {

double pX = (pixelStart + (p / locScale));
Expand All @@ -114,8 +113,10 @@ public static void drawExpandedInsertions(InsertionMarker insertionMarker,
if (pX > rect.getMaxX()) break;
else if (pX + dX < rect.getX()) continue;

char c = p < padding ? '-' : (char) bases.getByte(p - padding);

// idx can be out of range due to (1) padding, (2) no read sequence (sequence == *)
int idx = p - padding;
char c = idx >= 0 && idx < bases.length ? (char) bases.getByte(p - padding) :
padding > 0 ? '-' : '*';

Color color = null;
// TODO -- support bisulfite mode? Probably not possible as that depends on the reference
Expand Down
8 changes: 1 addition & 7 deletions src/main/java/org/broad/igv/sam/InsertionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void clear() {

public List<InsertionMarker> getInsertions(String chrName, double start, double end) {


Map<Integer, InsertionMarker> insertionMap = insertionMaps.get(chrName);
if(insertionMap == null ) return null;

Expand All @@ -81,11 +80,6 @@ public void setSelected(InsertionMarker insertionMarker) {
this.selectedInsertion = insertionMarker;
}

public InsertionMarker getSelectedInsertion(String chrName) {
return this.selectedInsertion;
}


public synchronized void processAlignments(String chr, List<Alignment> alignments) {

Genome genome = GenomeManager.getInstance().getCurrentGenome();
Expand All @@ -107,7 +101,7 @@ public synchronized void processAlignments(String chr, List<Alignment> alignment
AlignmentBlock[] blocks = a.getInsertions();
if (blocks != null) {
for (AlignmentBlock block : blocks) {
if (block.getBases() == null || block.getBases().length < minLength) continue;
if (block.getBasesLength() < minLength) continue;
Integer key = block.getStart();
InsertionMarker insertionMarker = insertionMap.get(key);
if (insertionMarker == null) {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/broad/igv/ui/panel/ReferenceFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,7 @@ private static int getChromosomeLength(String chrName) {
}

public void setExpandedInsertion(InsertionMarker im) {
InsertionMarker previousInsertion = this.expandedInsertion;
this.expandedInsertion = im;
if (im == null && previousInsertion != null) {
this.centerOnLocation(previousInsertion.position);
}
}

public InsertionMarker getExpandedInsertion() {
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/org/broad/igv/ui/panel/RulerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,11 @@ public void doMouseClick(MouseEvent evt) {
setCursor(Cursor.getDefaultCursor());
WaitCursorManager.CursorToken token = WaitCursorManager.showWaitCursor();
try {
boolean clickHandled = false;
for (final ClickLink link : clickLinks) {
if (link.region.contains(e.getPoint())) {
link.action.accept(link.value);
clickHandled = true;
}
}
if (!clickHandled && !isWholeGenomeView()) {
double newLocation = frame.getChromosomePosition(e);
frame.centerOnLocation(newLocation);
}

} finally {
WaitCursorManager.removeWaitCursor(token);
}
Expand Down

0 comments on commit a4cd2d5

Please sign in to comment.