Skip to content

Commit

Permalink
Make a few changes and refactors based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rickymagner committed Nov 28, 2023
1 parent 13f15b4 commit 7b70607
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@ public class SimpleCount implements Locatable, Feature {
public SimpleCount(final SimpleInterval interval,
final int count) {
this.interval = Utils.nonNull(interval);
this.count = ParamUtils.isPositiveOrZero(count, "Can't construct SimpleCount with negative count.");
this.count = ParamUtils.isPositiveOrZero(count, "Can't construct SimpleCount with negative count at " + interval.getContig() + ":" + interval.getStart() + "-" + interval.getEnd() + ".");
}

public SimpleCount(final NamedFeature namedFeature) {
this.interval = new SimpleInterval(namedFeature.getContig(), namedFeature.getStart(), namedFeature.getEnd());
try {
int count = Integer.parseInt(namedFeature.getName());
if (count > 0) {
this.count = count;
} else {
throw new UserException("Error parsing name into positive integer for feature at " + namedFeature.getContig() + "\t" + namedFeature.getStart() + "\t" + namedFeature.getEnd());
}
this(new SimpleInterval(namedFeature), Integer.parseInt(namedFeature.getName()));
} catch (NumberFormatException e) {
throw new UserException("Error parsing name into positive integer for feature at " + namedFeature.getContig() + "\t" + namedFeature.getStart() + "\t" + namedFeature.getEnd());
throw new IllegalArgumentException("Error parsing name into integer for feature at " + namedFeature.getContig() + ":" + namedFeature.getStart() + "-" + namedFeature.getEnd());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected ReadThreadingAssemblerArgumentCollection getReadThreadingAssemblerArgu
return new HaplotypeCallerReadThreadingAssemblerArgumentCollection();
}

@Argument(fullName = PLOIDY_REGIONS_NAME, shortName = PLOIDY_REGIONS_NAME, doc = "Interval file with column specifying desired ploidy for genotyping models.", optional = true)
@Argument(fullName = PLOIDY_REGIONS_NAME, shortName = PLOIDY_REGIONS_NAME, doc = "Interval file with column specifying desired ploidy for genotyping models. Overrides default ploidy and user-provided --ploidy argument in specific regions.", optional = true)
public FeatureDataSource<NamedFeature> ploidyRegions = null;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,11 +588,11 @@ public void writeHeader( final VariantContextWriter vcfWriter, final SAMSequence
}

/**
* Selects appropriate active region genotyping engine for given region
* Determines the appropriate ploidy to use at given site for different genotyping engines.
* @param region Current region of interest
* @return Active genotyping engine with correct ploidy setting for given region
* @return Ploidy value to use here given user inputs, or -1 if fall back to default
*/
private MinimalGenotypingEngine getLocalActiveGenotyper(Locatable region) {
private int getPloidyToUseAtThisSite(Locatable region) {
Set<SimpleCount> overlaps = this.ploidyRegionsOverlapDetector.getOverlaps(region);
// Return first engine for interval overlapping this region
if (!overlaps.isEmpty()) {
Expand All @@ -604,9 +604,23 @@ private MinimalGenotypingEngine getLocalActiveGenotyper(Locatable region) {
max = next;
}
}
return this.ploidyToActiveEvaluationGenotyper.get(max);
return max;
} else {
return -1; // Sentinel value to fall back to default genotyper
}
}

/**
* Selects appropriate active region genotyping engine for given region
* @param region Current region of interest
* @return Active genotyping engine with correct ploidy setting for given region
*/
private MinimalGenotypingEngine getLocalActiveGenotyper(Locatable region) {
int currentPloidy = getPloidyToUseAtThisSite(region);
if (currentPloidy == -1) {
return this.defaultActiveRegionEvaluationGenotyperEngine;
} else {
return this.ploidyToActiveEvaluationGenotyper.get(currentPloidy);
}
}

Expand All @@ -616,42 +630,14 @@ private MinimalGenotypingEngine getLocalActiveGenotyper(Locatable region) {
* @return Genotyping engine with correct ploidy setting for given region
*/
protected HaplotypeCallerGenotypingEngine getLocalGenotypingEngine(Locatable region) {
Set<SimpleCount> overlaps = this.ploidyRegionsOverlapDetector.getOverlaps(region);
// Return first engine for interval overlapping this region
if (!overlaps.isEmpty()) {
Iterator<SimpleCount> intervals = overlaps.iterator();
int max = intervals.next().getCount();
while (intervals.hasNext()) {
int next = intervals.next().getCount();
if (next > max) {
max = next;
}
}
return this.ploidyToGenotyperMap.get(max);
} else {
int currentPloidy = getPloidyToUseAtThisSite(region);
if (currentPloidy == -1) {
return this.defaultGenotypingEngine;
} else {
return this.ploidyToGenotyperMap.get(currentPloidy);
}
}

// /**
// * Selects appropriate genotyping engine for given region, either for active region determination or full genotyping.
// * @param ploidyEngineMap A HashMap of ploidy values to appropriate genotyping engines to choose from
// * @param defaultEngine The backup default engine to use if no overlap detected
// * @param ploidyOverlapDetector OverlapDetector to use for checking if region overlaps the given ploidy regions
// * @param region Current region of interest, e.g. AssemblyRegion
// * @return Genotyping engine with correct ploidy setting for given region
// */
// protected GenotypingEngine<StandardCallerArgumentCollection> getEngineForOverlap(HashMap<Integer, GenotypingEngine<StandardCallerArgumentCollection>> ploidyEngineMap,
// GenotypingEngine<StandardCallerArgumentCollection> defaultEngine, OverlapDetector ploidyOverlapDetector, Locatable region) {
// Set<SimpleCount> overlaps = ploidyOverlapDetector.getOverlaps(region);
// // Return first engine for interval overlapping this region
// if (overlaps.size() > 0) {
// return ploidyEngineMap.get(overlaps.iterator().next());
// } else {
// return defaultEngine;
// }
// }

/**
* Given a pileup, returns an ActivityProfileState containing the probability (0.0 to 1.0) that it's an "active" site.
*
Expand Down

0 comments on commit 7b70607

Please sign in to comment.