Skip to content

Commit

Permalink
Restore cluster menu option for 3rd gen alignments, renamed to "Clust…
Browse files Browse the repository at this point in the history
…er alignments". Fixes #1509
  • Loading branch information
jrobinso committed Jul 25, 2024
1 parent d4e05b7 commit 9c78e80
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/broad/igv/sam/Alignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ default ClippingCounts getClippingCounts(){
return ClippingCounts.fromCigar(getCigar());
}

default void setHaplotypeName(String hap) {}
default void setClusterName(String hap) {}

default String getHaplotypeName() {return null;}
default String getClusterName() {return null;}

default void setHapDistance(int dist) {};

default int getHapDistance() {return 0;}
default int getClusterDistance() {return 0;}

default Map<Integer, BaseModificationUtils> getBaseModificationMap() { return null;}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/broad/igv/sam/AlignmentPacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ private Object getGroupValue(Alignment al, AlignmentTrack.RenderOptions renderOp
String readNameParts[], movieName, zmw;

switch (groupBy) {
case HAPLOTYPE:
return al.getHaplotypeName();
case CLUSTER:
return al.getClusterName();
case STRAND:
return al.isNegativeStrand() ? "-" : "+";
case SAMPLE:
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/broad/igv/sam/AlignmentTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public enum GroupOption {
INSERTION_AT_POS("insertion at position", true),
MOVIE("movie"),
ZMW("ZMW"),
HAPLOTYPE("haplotype"),
CLUSTER("cluster"),
READ_ORDER("read order"),
LINKED("linked"),
PHASE("phase"),
Expand Down Expand Up @@ -1711,7 +1711,11 @@ public void unmarshalXML(Element element, Integer version) {
sortOption = SortOption.valueOf((element.getAttribute("sortOption")));
}
if (element.hasAttribute("groupByOption")) {
groupByOption = GroupOption.valueOf(element.getAttribute("groupByOption"));
String value = element.getAttribute("groupByOption");
if(value.equals("HAPLOTYPE")) {
value = "CLUSTER"; // Backward compatibility
}
groupByOption = GroupOption.valueOf(value);
}
if (element.hasAttribute("shadeAlignmentsByOption")) {
shadeAlignmentsOption = ShadeAlignmentsOption.valueOf(element.getAttribute("shadeAlignmentsByOption"));
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/org/broad/igv/sam/AlignmentTrackMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import htsjdk.samtools.SAMTag;
import org.broad.igv.Globals;
import org.broad.igv.feature.Locus;
import org.broad.igv.feature.Range;
import org.broad.igv.feature.Strand;
import org.broad.igv.jbrowse.CircularViewUtilities;
Expand Down Expand Up @@ -95,10 +94,6 @@ class AlignmentTrackMenu extends IGVPopupMenu {
// Experiment type (RNA, THIRD GEN, OTHER)
addSeparator();
addExperimentTypeMenuItem();
// if (alignmentTrack.getExperimentType() == AlignmentTrack.ExperimentType.THIRD_GEN) {
// addHaplotype(e);
// }


// Group, sort, color, shade, and pack
addSeparator();
Expand Down Expand Up @@ -186,6 +181,12 @@ class AlignmentTrackMenu extends IGVPopupMenu {
add(sashimi);
}

// Experimental items
if (alignmentTrack.getExperimentType() == AlignmentTrack.ExperimentType.THIRD_GEN) {
addSeparator();
addClusterItem(e);
}

// Show alignments, coverage, splice junctions
addSeparator();
addShowItems();
Expand Down Expand Up @@ -233,9 +234,9 @@ private void addShowDiagram(final TrackClickEvent e, final Alignment clickedAlig
}


private void addHaplotype(TrackClickEvent e) {
private void addClusterItem(TrackClickEvent e) {

JMenuItem item = new JMenuItem("Cluster (phase) alignments");
JMenuItem item = new JMenuItem("Cluster alignments *EXPERIMENTAL*");

final ReferenceFrame frame;
if (e.getFrame() == null && FrameManager.getFrames().size() == 1) {
Expand Down Expand Up @@ -269,17 +270,14 @@ private void addHaplotype(TrackClickEvent e) {
final int end = (int) frame.getEnd();

AlignmentInterval interval = dataManager.getLoadedInterval(frame);
HaplotypeUtils haplotypeUtils = new HaplotypeUtils(interval);
boolean success = haplotypeUtils.clusterAlignments(frame.getChrName(), start, end, nClusters);
ClusterUtils clusterUtils = new ClusterUtils(interval);
boolean success = clusterUtils.clusterAlignments(frame.getChrName(), start, end, nClusters);

if (success) {
groupAlignments(AlignmentTrack.GroupOption.HAPLOTYPE, null, null);
groupAlignments(AlignmentTrack.GroupOption.CLUSTER, null, null);
alignmentTrack.repaint();
}

//dataManager.sortRows(SortOption.HAPLOTYPE, frame, (end + start) / 2, null);
//AlignmentTrack.repaint();

});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import org.broad.igv.feature.genome.GenomeManager;
import org.broad.igv.logging.*;
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.ui.util.MessageUtils;

import java.util.*;
Expand All @@ -15,14 +14,14 @@
* @author Jim Robinson
*/

public class HaplotypeUtils {
public class ClusterUtils {

private static Logger log = LogManager.getLogger(HaplotypeUtils.class);
private static Logger log = LogManager.getLogger(ClusterUtils.class);

private final AlignmentInterval alignmentInterval;


public HaplotypeUtils(AlignmentInterval alignmentInterval) {
public ClusterUtils(AlignmentInterval alignmentInterval) {
this.alignmentInterval = alignmentInterval;
}

Expand Down Expand Up @@ -54,7 +53,7 @@ public boolean clusterAlignments(String chr, int start, int end, int nClasses) {

// Clear any existing names
for(Alignment a : this.alignmentInterval.getAlignments()) {
a.setHaplotypeName("NONE");
a.setClusterName("?");
}

// Label alignments
Expand Down Expand Up @@ -126,7 +125,7 @@ public boolean clusterAlignments(String chr, int start, int end, int nClasses) {

List<Alignment> alignments = labelAlignmentMap.get(l);
for (Alignment a : alignments) {
a.setHaplotypeName(label);
a.setClusterName(label);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/broad/igv/sam/SAMAlignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,9 @@ public String getAlignmentValueString(double position, int mouseX, AlignmentTrac
int basePosition = (int) position;
StringBuffer buf = new StringBuffer();

if (getHaplotypeName() != null) {
buf.append("Hap name: " + getHaplotypeName() + "<br>");
buf.append("Dist: " + getHapDistance() + "<br>");
if (getClusterName() != null) {
buf.append("Cluster name: " + getClusterName() + "<br>");
buf.append("Dist: " + getClusterDistance() + "<br>");
}

boolean atInsertion = false;
Expand Down Expand Up @@ -1215,12 +1215,12 @@ private static boolean operatorIsMatch(boolean showSoftClipped, char operator) {
String haplotypeName;

@Override
public void setHaplotypeName(String hap) {
public void setClusterName(String hap) {
haplotypeName = hap;
}

@Override
public String getHaplotypeName() {
public String getClusterName() {
return haplotypeName;
}

Expand All @@ -1232,7 +1232,7 @@ public void setHapDistance(int dist) {
}

@Override
public int getHapDistance() {
public int getClusterDistance() {
return hapDistance;
}

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/broad/igv/sam/SortOption.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package org.broad.igv.sam;

import htsjdk.samtools.SAMTag;
import htsjdk.samtools.util.Locatable;
import org.broad.igv.feature.genome.ChromosomeNameComparator;

import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.function.ToIntFunction;

Expand Down Expand Up @@ -134,7 +131,7 @@ Comparator<Alignment> getAlignmentComparator(final int center, final String tag,
}, HAPLOTYPE {
@Override
Comparator<Alignment> getAlignmentComparator(final int center, final String tag, final byte referenceBase) {
return Comparator.comparingInt(Alignment::getHapDistance);
return Comparator.comparingInt(Alignment::getClusterDistance);
}
}, READ_ORDER {
@Override
Expand Down

0 comments on commit 9c78e80

Please sign in to comment.