Skip to content

Commit

Permalink
* Catch errors in sampling alignments to determine experiment type.
Browse files Browse the repository at this point in the history
* Null check in IGVReferenceSource -- can occur when alignments in CRAM files reference sequences no present in loaded genome.
* Revert name change to menu item for downloading hosted genomes
  • Loading branch information
jrobinso committed Sep 30, 2024
1 parent 2838c30 commit 5629b43
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
47 changes: 27 additions & 20 deletions src/main/java/org/broad/igv/sam/AlignmentDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,29 +378,36 @@ private void updateBaseModfications(List<Alignment> alignments) {
}

public AlignmentTrack.ExperimentType inferType() {
if (this.inferredType != null) {
return this.inferredType;
}

ReadStats readStats = new ReadStats();
List<Alignment> sample = AlignmentUtils.firstAlignments(reader, 100);
for (Alignment a : sample) {
readStats.addAlignment(a);
}
inferredType = readStats.inferType();

if (inferredType == AlignmentTrack.ExperimentType.THIRD_GEN) {
return inferredType;
} else {
// Get a larger sample to distinguish RNA-Seq
readStats = new ReadStats();
sample = AlignmentUtils.firstAlignments(reader, 2000);
for (Alignment a : sample) {
readStats.addAlignment(a);
if (this.inferredType == null) {
try {
ReadStats readStats = new ReadStats();
List<Alignment> sample = AlignmentUtils.firstAlignments(reader, 100);
for (Alignment a : sample) {
readStats.addAlignment(a);
}
inferredType = readStats.inferType();

if (inferredType == AlignmentTrack.ExperimentType.THIRD_GEN) {
return inferredType;
} else {
// Get a larger sample to distinguish RNA-Seq
readStats = new ReadStats();
sample = AlignmentUtils.firstAlignments(reader, 2000);
for (Alignment a : sample) {
readStats.addAlignment(a);
}
inferredType = readStats.inferType();
return inferredType;
}
} catch (Exception e) {
// Ignore errors, inferring alignment type is not essential.
log.error("Error inferring alignment type", e);
inferredType = AlignmentTrack.ExperimentType.UNKOWN;
}
inferredType = readStats.inferType();
return inferredType;
}

return inferredType;
}

private AlignmentTrack.ExperimentType getExperimentType() {
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/broad/igv/sam/AlignmentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static AlignmentBlockImpl buildAlignmentBlock(char operator,
}


public static List<Alignment> firstAlignments(AlignmentReader reader, int count) {
public static List<Alignment> firstAlignments(AlignmentReader reader, int count) throws IOException {

List<Alignment> alignments = new ArrayList<>();
CloseableIterator<Alignment> iter = null;
Expand All @@ -244,12 +244,9 @@ public static List<Alignment> firstAlignments(AlignmentReader reader, int count)
alignments.add(iter.next());
}
return alignments;
} catch (IOException e) {

} finally {
iter.close();
}
return alignments;
}


Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/broad/igv/sam/cram/IGVReferenceSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.broad.igv.ui.IGV;
import org.broad.igv.util.ObjectCache;

import java.util.Arrays;
import java.util.HashMap;

/**
Expand All @@ -52,7 +53,7 @@ public class IGVReferenceSource implements CRAMReferenceSource {

@Override
public byte[] getReferenceBases(SAMSequenceRecord record, boolean tryNameVariants) {
return getReferenceBasesByRegion(record, 0, record.getSequenceLength());
return getReferenceBasesByRegion(record, 0, record.getSequenceLength());
}

@Override
Expand All @@ -62,9 +63,11 @@ public byte[] getReferenceBasesByRegion(final SAMSequenceRecord sequenceRecord,
String chrName = currentGenome.getCanonicalChrName(name);
byte[] bases = currentGenome.getSequence(chrName, zeroBasedStart, zeroBasedStart + requestedRegionLength, true);

// CRAM spec requires upper case
for (int i = 0; i < bases.length; i++) {
if (bases[i] >= 97) bases[i] -= 32;
if (bases != null) {
// CRAM spec requires upper case
for (int i = 0; i < bases.length; i++) {
if (bases[i] >= 97) bases[i] -= 32;
}
}
return bases;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/ui/IGVMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ private JMenu createGenomesMenu() {

JMenu menu = new JMenu("Genomes");

loadGenomeFromServerMenuItem = new JMenuItem("Download Hosted Genome...");
loadGenomeFromServerMenuItem = new JMenuItem("Select Hosted Genome...");
loadGenomeFromServerMenuItem.addActionListener(e -> GenomeSelectionDialog.selectGenomesFromServer());
loadGenomeFromServerMenuItem.setToolTipText(LOAD_GENOME_SERVER_TOOLTIP);
menu.add(loadGenomeFromServerMenuItem);
Expand Down

0 comments on commit 5629b43

Please sign in to comment.