Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
Release 1.40.0.1613+master
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-tc-bioinfo committed Apr 8, 2019
2 parents 6571108 + 01584bb commit 5d187fc
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Src/Canvas/CanvasPedigreeCaller/CanvasPedigreeCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ private double GetSegmentSetLogLikelihood(ISampleMap<OverlappingSegmentsRegion>
}
foreach (var canvasSegment in canvasSegments)
{
var copyNumbersLikelihoods = _copyNumberLikelihoodCalculator.GetCopyNumbersLikelihoods(canvasSegment, samplesInfo, copyNumberModel);
var copyNumbersLikelihoods = _copyNumberLikelihoodCalculator.GetCopyNumbersLikelihoods(canvasSegment, samplesInfo, copyNumberModel, _callerParameters.NumberOfTrimmedBins);
var (_, likelihoods) = GetCopyNumbersNoPedigreeInfo(canvasSegment, copyNumbersLikelihoods);
segmentSetLogLikelihood += likelihoods.MaximalLogLikelihood;
}
Expand Down
26 changes: 21 additions & 5 deletions Src/Canvas/CanvasPedigreeCaller/CopyNumberLikelihoodCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public CopyNumberLikelihoodCalculator(int maximumCopyNumber)
/// Use likelihoods as only median point estimator is used
/// </summary>
public ISampleMap<Dictionary<Genotype, double>> GetCopyNumbersLikelihoods(ISampleMap<CanvasSegment> canvasSegments, ISampleMap<SampleMetrics> samplesInfo,
ISampleMap<ICopyNumberModel> copyNumberModel)
ISampleMap<ICopyNumberModel> copyNumberModel, int numberOfTrimmedBins)
{
const int bins2Remove = 5;
var genotypes = Enumerable.Range(0, _maximumCopyNumber).Select(Genotype.Create).ToList();
const double maxCoverageMultiplier = 3.0;
var singleSampleLikelihoods = new SampleMap<Dictionary<Genotype, double>>();
Expand All @@ -33,10 +32,27 @@ public ISampleMap<Dictionary<Genotype, double>> GetCopyNumbersLikelihoods(ISampl

foreach (var genotypeCopyNumber in genotypes)
{
double cvg = Math.Min(canvasSegments[sampleId].TruncatedMedianCount(numberOfTrimmedBins),
samplesInfo[sampleId].MeanCoverage * maxCoverageMultiplier);
// In case we run into out-of-range trouble again (CANV-694), print details
{
int intcvg = Convert.ToInt32(cvg);
int coverageBound = copyNumberModel[sampleId].GetCoverageBound();
double truncatedDepth = canvasSegments[sampleId].TruncatedMedianCount(numberOfTrimmedBins);
double meanTimesThree = samplesInfo[sampleId].MeanCoverage * maxCoverageMultiplier;
int maxAllowedCN = copyNumberModel[sampleId].GetMaxCopyNumber();
if ( intcvg >= coverageBound || genotypeCopyNumber.TotalCopyNumber > maxAllowedCN)
{
throw new ArgumentException(
$"Tried to look up bad depth or CN for {sampleId}: depth {intcvg} CN {genotypeCopyNumber.TotalCopyNumber}" +
$" where max handled values are {coverageBound} and {maxAllowedCN} respectively;" +
$" original depth was {truncatedDepth}, mean * 3 was {meanTimesThree};" +
$" segment {canvasSegments[sampleId].Chr}:{canvasSegments[sampleId].Begin}-{canvasSegments[sampleId].End}");

}
}
double currentLikelihood =
copyNumberModel[sampleId].GetTotalCopyNumberLikelihoods(
Math.Min(canvasSegments[sampleId].TruncatedMedianCount(bins2Remove),
samplesInfo[sampleId].MeanCoverage * maxCoverageMultiplier), genotypeCopyNumber);
copyNumberModel[sampleId].GetTotalCopyNumberLikelihoods(cvg, genotypeCopyNumber);
currentLikelihood = Double.IsNaN(currentLikelihood) || Double.IsInfinity(currentLikelihood)
? 0
: currentLikelihood;
Expand Down
12 changes: 12 additions & 0 deletions Src/Canvas/CanvasPedigreeCaller/HaplotypeCopyNumberModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public HaplotypeCopyNumberModel(List<List<double>> cnDistribution, Tuple<List<do
_logFactorial.Add(Math.Log(i) + _logFactorial.Last());
}

public int GetCoverageBound()
{
// _maxAlleleCounts is twice the first value for which _cnDistribution is undefined
// see HaplotypeCopyNumberModelFactory::CreateModel() for details
return _maxAlleleCounts / 2;
}

public int GetMaxCopyNumber()
{
return _cnDistribution.Count - 1;
}

public double GetTotalCopyNumberLikelihoods(double segmentMedianBinCoverage, Genotype totalCopyNumberGenotype)
{
return _cnDistribution.Select(x => x[Convert.ToInt32(segmentMedianBinCoverage)]).ElementAt(totalCopyNumberGenotype.TotalCopyNumber);
Expand Down
2 changes: 1 addition & 1 deletion Src/Canvas/CanvasPedigreeCaller/HaplotypeVariantCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public HaplotypeVariantCaller(CopyNumberLikelihoodCalculator copyNumberLikelihoo
public void CallVariant(ISampleMap<CanvasSegment> canvasSegments, ISampleMap<SampleMetrics> samplesInfo,
ISampleMap<ICopyNumberModel> copyNumberModel, PedigreeInfo pedigreeInfo)
{
var coverageLikelihoods = _copyNumberLikelihoodCalculator.GetCopyNumbersLikelihoods(canvasSegments, samplesInfo, copyNumberModel);
var coverageLikelihoods = _copyNumberLikelihoodCalculator.GetCopyNumbersLikelihoods(canvasSegments, samplesInfo, copyNumberModel, _callerParameters.NumberOfTrimmedBins);
// if number and properties of SNPs in the segment are above threshold, calculate likelihood from SNPs and merge with
// coverage likelihood to form merged likelihoods
int nBalleles = canvasSegments.Values.First().Balleles.Size();
Expand Down
2 changes: 2 additions & 0 deletions Src/Canvas/CanvasPedigreeCaller/ICopyNumberModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public interface ICopyNumberModel
{
double GetGenotypeLogLikelihood(Balleles segmentAlleleReadCounts, PhasedGenotype phasedGenotype);
double GetTotalCopyNumberLikelihoods(double segmentMedianBinCoverage, Genotype totalCopyNumberGenotype);
int GetCoverageBound();
int GetMaxCopyNumber();
}

public interface ICopyNumberModelFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PedigreeCallerParameters
public int MaxNumOffspringGenotypes { get; set; } = 500;
public double DeNovoRate { get; set; } = 0.00001;
public int MinimumCallSize { get; set; } = 2000;
public int NumberOfTrimmedBins { get; set; } = 2;
public int NumberOfTrimmedBins { get; set; } = 5;
public int MaxCoreNumber { get; set; } = 30;
[JsonProperty("DefaultCaller")]
[JsonConverter(typeof(StringEnumConverter))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"MaxNumOffspringGenotypes": 500,
"DeNovoRate": 0.00001,
"MinimumCallSize": 2000,
"NumberOfTrimmedBins": 2,
"NumberOfTrimmedBins": 5,
"MaxCoreNumber": 30,
"DefaultCaller": "VariantCaller"
}
2 changes: 1 addition & 1 deletion Src/Canvas/CanvasPedigreeCaller/VariantCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static int GetCnState(ISampleMap<CanvasSegment> canvasSegmentsSet, Sampl
public void CallVariant(ISampleMap<CanvasSegment> canvasSegments, ISampleMap<SampleMetrics> samplesInfo,
ISampleMap<ICopyNumberModel> copyNumberModel, PedigreeInfo pedigreeInfo)
{
var singleSampleLikelihoods = _copyNumberLikelihoodCalculator.GetCopyNumbersLikelihoods(canvasSegments, samplesInfo, copyNumberModel);
var singleSampleLikelihoods = _copyNumberLikelihoodCalculator.GetCopyNumbersLikelihoods(canvasSegments, samplesInfo, copyNumberModel, _callerParameters.NumberOfTrimmedBins);

(var pedigreeCopyNumbers, var pedigreeLikelihoods) = GetPedigreeCopyNumbers(pedigreeInfo, singleSampleLikelihoods);

Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version: 1.39.0
version: 1.40.0
configuration: Release

0 comments on commit 5d187fc

Please sign in to comment.