Skip to content

Commit

Permalink
Refactor "copy read details" code, and minor reformatting of output.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Oct 21, 2024
1 parent 20da885 commit af07c3b
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 48 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/broad/igv/sam/Alignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ default int getLeadingHardClipLength() {

default String getLibrary(){ return null;}

String getClipboardString(double location, int mouseX);
default String getClipboardString(double location, int mouseX) {
return getValueString(location, mouseX, null);
}

default void finish(){};

Expand Down
15 changes: 5 additions & 10 deletions src/main/java/org/broad/igv/sam/AlignmentTrackMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ private void addDuplicatesMenuItem() {
mi.setSelected(previous == option);
mi.addActionListener(aEvt -> {
renderOptions.setDuplicatesOption(option);
if(previous != option) {
if (previous.filtered != option.filtered){
if (previous != option) {
if (previous.filtered != option.filtered) {
// duplicates are filtered out when loading the read data so a reload has to be performed in this case
IGVEventBus.getInstance().post(new AlignmentTrackEvent(AlignmentTrackEvent.Type.RELOAD));
} else {
Expand Down Expand Up @@ -1220,19 +1220,14 @@ void addThirdGenItems(Alignment clickedAlignment, final TrackClickEvent tce) {
private void copyToClipboard(final TrackClickEvent e, Alignment alignment, double location, int mouseX) {

if (alignment != null) {
StringBuilder buf = new StringBuilder();
buf.append(alignment.getClipboardString(location, mouseX)
final String clipboardString = alignment.getClipboardString(location, mouseX)
.replace("<b>", "")
.replace("</b>", "")
.replace("<br>", "\n")
.replace("<br/>", "\n")
.replace("<hr>", "\n------------------\n")
.replace("<hr/>", "\n------------------\n"));
buf.append("\n");
buf.append("Alignment start position = ").append(alignment.getChr()).append(":").append(alignment.getAlignmentStart() + 1);
buf.append("\n");
buf.append(alignment.getReadSequence());
StringSelection stringSelection = new StringSelection(buf.toString());
.replace("<hr/>", "\n------------------\n");
StringSelection stringSelection = new StringSelection(clipboardString);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, null);
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/broad/igv/sam/DotAlignedAlignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ public LocusScore copy() {
return this;
}

public String getClipboardString(double location, int mouseX) {
return getValueString(location, mouseX, (WindowFunction) null);
}

public String getValueString(double position, int mouseX, WindowFunction windowFunction) {
return readName + "<br>Read length = " + (getEnd() - getStart());
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/broad/igv/sam/FeatureWrappedAlignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,6 @@ public LocusScore copy() {
return this;
}

public String getClipboardString(double location, int mouseX) {
return getValueString(location, mouseX, (WindowFunction) null);
}

public String getValueString(double position, int mouseX, WindowFunction windowFunction) {
return readName + "<br>Read length = " + (getEnd() - getStart());
}
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/org/broad/igv/sam/LinkedAlignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.*;

/**
* Class for experimenting with 10X linked reads.
* Represents a collection of alignments linked by a tag or read name
*/

public class LinkedAlignment implements Alignment {
Expand Down Expand Up @@ -363,11 +363,6 @@ public String getSample() {
return sample;
}

@Override
public String getClipboardString(double location, int mouseX) {
return null;
}

@Override
public void finish() {
alignments.sort(ALIGNMENT_START_COMPARATOR);
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/org/broad/igv/sam/PairedAlignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,6 @@ public String getAlignmentValueString(double position, int mouseX, AlignmentTrac
return buf.toString();
}


public String getClipboardString(double position, int mouseX) {
StringBuffer buf = new StringBuffer();
buf.append("<b>Left alignment</b><br/>");
buf.append(firstAlignment.getClipboardString(position, mouseX));
if (secondAlignment != null) {
buf.append("<br/><b>Right alignment</b><br/>");
buf.append(secondAlignment.getClipboardString(position, mouseX));
}
return buf.toString();
}
////////////////////////////////////////////////////////////

public boolean contains(double location) {
return location >= start && location <= end;
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/broad/igv/sam/ReducedMemoryAlignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ public LocusScore copy() {
return this;
}

public String getClipboardString(double location, int mouseX) {
return getValueString(location, mouseX, (WindowFunction) null);
}

public String getValueString(double position, int mouseX, WindowFunction ignored) {

StringBuffer buf = new StringBuffer();
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/org/broad/igv/sam/SAMAlignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import htsjdk.samtools.SAMReadGroupRecord;
import htsjdk.samtools.SAMRecord;
import htsjdk.samtools.SAMTag;
import htsjdk.samtools.util.SequenceUtil;
import org.broad.igv.logging.*;
import org.broad.igv.Globals;
import org.broad.igv.feature.Strand;
Expand Down Expand Up @@ -658,7 +659,6 @@ private static List<CigarOperator> buildOperators(String cigarString) {
prevOp = new CigarOperator(nBases, op);
operators.add(prevOp);
}

}
}
return operators;
Expand All @@ -668,7 +668,22 @@ private static List<CigarOperator> buildOperators(String cigarString) {

@Override
public String getClipboardString(double location, int mouseX) {
return getAlignmentValueString(location, mouseX, null);

StringBuilder buf = new StringBuilder();

String popupTextString = getAlignmentValueString(location, mouseX, null);
buf.append(popupTextString);

buf.append("----------------------");
final String readSequence = getReadSequence();
final String origSequence = isNegativeStrand() ? SequenceUtil.reverseComplement(readSequence) : readSequence;
buf.append("\n\nRead sequence = ");
buf.append(readSequence);
buf.append("\n\nOrig sequence = ");
buf.append(origSequence);
buf.append("\n");

return buf.toString();
}

private Integer positionToReadIndex(double position) {
Expand Down Expand Up @@ -697,6 +712,7 @@ public String getAlignmentValueString(double position, int mouseX, AlignmentTrac

boolean atInsertion = false;
boolean atBaseMod = false;

// First check insertions. Position is zero based, block coords 1 based
if (this.insertions != null) {
for (AlignmentBlock block : this.insertions) {
Expand Down
4 changes: 0 additions & 4 deletions src/test/java/org/broad/igv/sam/BisulfiteBaseInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,5 @@ public String getLibrary() {
return library;
}

@Override
public String getClipboardString(double location, int mouseX) {
return null;
}
}
}

0 comments on commit af07c3b

Please sign in to comment.