Ejemplo n.º 1
0
        [InlineData(1e-6)] // Background should not be counted
        public void StepNotMoreThanStepCount(double tauW)
        {
            // Arrange
            var s1 = new Bed <Peak>();

            s1.Add(new Peak(10, 20, 1E-4), _chr, _strand);
            s1.Add(new Peak(30, 40, 1E-5), _chr, _strand);
            s1.Add(new Peak(50, 60, 1E-6), _chr, _strand);
            s1.Add(new Peak(70, 80, 1E-7), _chr, _strand);
            s1.Add(new Peak(90, 99, 1E-8), _chr, _strand);

            var s2 = new Bed <Peak>();

            s2.Add(new Peak(11, 18, 1E-4), _chr, _strand);
            s2.Add(new Peak(33, 38, 1E-5), _chr, _strand);
            s2.Add(new Peak(55, 58, 1E-6), _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, s1);
            mspc.AddSample(1, s2);

            var messages = new List <ProgressReport>();

            mspc.StatusChanged += (object sender, ValueEventArgs e) => messages.Add(e.Value);

            // Act
            mspc.RunAsync(new Config(ReplicateType.Biological, tauW, tauW, tauW, 2, 0.05F, MultipleIntersections.UseLowestPValue));
            mspc.Done.WaitOne();

            // Assert
            Assert.DoesNotContain(messages, x => x.Step > x.StepCount);
        }
Ejemplo n.º 2
0
        public void T1()
        {
            // Arrange
            var sA  = new Bed <Peak>();
            var r11 = new Peak(left: 10, right: 20, value: 1e-4, name: "r11");

            sA.Add(r11, _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 5, right: 12, value: 1e-4, name: "r21"), _chr, _strand);
            sB.Add(new Peak(left: 18, right: 25, value: 1e-4, name: "r22"), _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-3, 1e-8, 1e-8, 2, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            Assert.True(res[0].Chromosomes[_chr].Get(Attributes.Discarded).Count() == 1);
            Assert.False(res[0].Chromosomes[_chr].Get(Attributes.Confirmed).Any());
            Assert.True(res[0].Chromosomes[_chr].Get(Attributes.Discarded).ToList()[0].Source.CompareTo(r11) == 0);
        }
Ejemplo n.º 3
0
        public void ComputeAdjustedPValue()
        {
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 0.01), _chr, _strand);
            sA.Add(new Peak(left: 100, right: 200, value: 0.001), _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 5, right: 12, value: 0.01), _chr, _strand);
            sB.Add(new Peak(left: 50, right: 120, value: 0.001), _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-1, 1e-2, 1e-2, 2, 0.05F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            Assert.True(res[0].Chromosomes[_chr].Get(Attributes.TruePositive).First().AdjPValue == 0.01);
            Assert.True(res[0].Chromosomes[_chr].Get(Attributes.TruePositive).Last().AdjPValue == 0.002);
        }
Ejemplo n.º 4
0
        private Mspc <Peak> InitializeMSPC()
        {
            var sA = new Bed <Peak>();

            sA.Add(r11, "chr1", '*');
            sA.Add(r12, "chr1", '*');

            var sB = new Bed <Peak>();

            sB.Add(r21, "chr1", '*');
            sB.Add(r22, "chr1", '*');
            sB.Add(r23, "chr1", '*');

            var sC = new Bed <Peak>();

            sC.Add(r31, "chr1", '*');
            sC.Add(r32, "chr1", '*');
            sC.Add(r33, "chr1", '*');

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);
            mspc.AddSample(2, sC);
            return(mspc);
        }
Ejemplo n.º 5
0
        public void AssignFalsePositive()
        {
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 1e-6), _chr, _strand);
            sA.Add(new Peak(left: 100, right: 200, value: 1e-8), _chr, _strand);
            sA.Add(new Peak(left: 1000, right: 2000, value: 1e-10), _chr, _strand);
            sA.Add(new Peak(left: 10000, right: 20000, value: 1e-12), _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 5, right: 12, value: 1e-7), _chr, _strand);
            sB.Add(new Peak(left: 50, right: 120, value: 1e-9), _chr, _strand);
            sB.Add(new Peak(left: 500, right: 1200, value: 1e-11), _chr, _strand);
            sB.Add(new Peak(left: 5000, right: 12000, value: 1e-13), _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-4, 1e-6, 1e-6, 2, 5e-10F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            foreach (var sample in res)
            {
                Assert.True(sample.Value.Chromosomes[_chr].Count(Attributes.FalsePositive) == 2);
            }
        }
Ejemplo n.º 6
0
        private Mspc SetupMSPC(int peakCount = 4, float alpha = 5e-10F)
        {
            var sA = new Bed <Peak>();

            for (int i = 0; i < peakCount; i++)
            {
                sA.Add(_setA[i], _chrs[i], _strand);
            }

            var sB = new Bed <Peak>();

            for (int i = 0; i < peakCount; i++)
            {
                sB.Add(_setB[i], _chrs[i], _strand);
            }

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-4, 1e-8, 1e-8, 2, alpha, MultipleIntersections.UseLowestPValue);

            mspc.Run(config);
            return(mspc);
        }
Ejemplo n.º 7
0
        public void DoNotCountOverlapsFromSameSample()
        {
            // Arrange
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 0.01, hashSeed: "0"), "chr1", '*');
            sA.Add(new Peak(left: 10, right: 20, value: 0.01, hashSeed: "1"), "chr1", '*');
            sA.Add(new Peak(left: 10, right: 20, value: 0.01, hashSeed: "2"), "chr1", '*');
            sA.Add(new Peak(left: 10, right: 20, value: 0.01, hashSeed: "3"), "chr1", '*');

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 5, right: 12, value: 0.01), "chr1", '*');

            var sC = new Bed <Peak>();

            sC.Add(new Peak(left: 18, right: 25, value: 0.01), "chr1", '*');

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);
            mspc.AddSample(2, sC);

            var config = new Config(ReplicateType.Biological, 1, 1, 1, 5, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            Assert.True(res[0].Chromosomes["chr1"].Count(Attributes.Confirmed) == 0);
        }
Ejemplo n.º 8
0
        public void AssertCorrectPeakIsTaggedAsFalsePositive()
        {
            var sA  = new Bed <Peak>();
            var r11 = new Peak(left: 10, right: 20, value: 1e-6);

            sA.Add(r11, _chr, _strand);
            sA.Add(new Peak(left: 100, right: 200, value: 1e-8), _chr, _strand);
            sA.Add(new Peak(left: 1000, right: 2000, value: 1e-10), _chr, _strand);
            sA.Add(new Peak(left: 10000, right: 20000, value: 1e-12), _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 5, right: 12, value: 1e-7), _chr, _strand);
            sB.Add(new Peak(left: 50, right: 120, value: 1e-9), _chr, _strand);
            sB.Add(new Peak(left: 500, right: 1200, value: 1e-11), _chr, _strand);
            sB.Add(new Peak(left: 5000, right: 12000, value: 1e-13), _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-4, 1e-6, 1e-6, 2, 5e-10F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            Assert.True(res[0].Chromosomes[_chr].Get(Attributes.FalsePositive).First().Source.Equals(r11));
        }
Ejemplo n.º 9
0
        public void StringentNonOverlappingPeaks()
        {
            // Arrange
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 1e-9), _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 50, right: 60, value: 1e-12), _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-4, 1e-8, 1e-4, 2, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            foreach (var s in res)
            {
                Assert.True(s.Value.Chromosomes[_chr].Count(Attributes.Stringent) == 1);
            }
        }
Ejemplo n.º 10
0
        public void ThreePeaksTwoOverlapping(int c, int expected)
        {
            // Arrange
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 0.01), "chr1", '*');

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 5, right: 12, value: 0.01), "chr1", '*');

            var sC = new Bed <Peak>();

            sC.Add(new Peak(left: 18, right: 25, value: 0.01), "chr1", '*');

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);
            mspc.AddSample(2, sC);

            var config = new Config(ReplicateType.Biological, 1, 1, 1, c, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            Assert.True(new[]
            {
                res[0].Chromosomes["chr1"].Get(Attributes.Confirmed).Count(),
                res[1].Chromosomes["chr1"].Get(Attributes.Confirmed).Count(),
                res[2].Chromosomes["chr1"].Get(Attributes.Confirmed).Count()
            }.All(x => x == expected));
        }
Ejemplo n.º 11
0
        public void OnlyOnePeakPerSampleIsConsideredForC()
        {
            // Arrange
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 0.01), "chr1", '*');

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 5, right: 12, value: 0.01), "chr1", '*');
            sB.Add(new Peak(left: 14, right: 22, value: 0.01), "chr1", '*');

            var sC = new Bed <Peak>();

            sC.Add(new Peak(left: 24, right: 25, value: 0.01), "chr1", '*');

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);
            mspc.AddSample(2, sC);

            var config = new Config(ReplicateType.Biological, 1, 1, 1, 3, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            Assert.False(res[0].Chromosomes["chr1"].Get(Attributes.Confirmed).Any());
        }
Ejemplo n.º 12
0
        public void BackgroundOverlappingNonBackground()
        {
            // Arrange
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 1e-2), _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 50, right: 60, value: 1e-8), _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-4, 1e-8, 1e-4, 2, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            Assert.True(
                res[0].Chromosomes[_chr].Count(Attributes.Background) == 1 &&
                res[1].Chromosomes[_chr].Count(Attributes.Background) == 0);
        }
Ejemplo n.º 13
0
        public void ConfirmTwoPeaksWithVeryLowPValue()
        {
            // Arrange
            var sA  = new Bed <Peak>();
            var sAP = new Peak(left: 10, right: 20, value: 5e-321);

            sA.Add(sAP, _chr, _strand);

            var sB  = new Bed <Peak>();
            var sBP = new Peak(left: 5, right: 15, value: 5e-323);

            sB.Add(sBP, _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-4, 1e-8, 1e-8, 2, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            Assert.True(
                res[0].Chromosomes[_chr].Get(Attributes.Confirmed).Any() &&
                res[1].Chromosomes[_chr].Get(Attributes.Confirmed).Any());
        }
Ejemplo n.º 14
0
        public void IntervalsWithExactSameCoordinates()
        {
            // Arrange
            int sampleCount = 22;
            var mspc        = new Mspc();

            for (uint i = 0; i < sampleCount - 2; i++)
            {
                var bed = new Bed <Peak>();
                bed.Add(new Peak(10, 20, 0.01), "chr1", '*');
                mspc.AddSample(i, bed);
            }

            var bedB = new Bed <Peak>();

            bedB.Add(new Peak(8, 12, 0.01), "chr1", '*');
            mspc.AddSample((uint)sampleCount - 2, bedB);

            var bedC = new Bed <Peak>();

            bedC.Add(new Peak(18, 25, 0.01), "chr1", '*');
            mspc.AddSample((uint)sampleCount - 1, bedC);

            var config = new Config(ReplicateType.Biological, 1, 1, 1, sampleCount, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            for (uint i = 0; i < sampleCount; i++)
            {
                Assert.True(res[i].Chromosomes["chr1"].Count(Attributes.Confirmed) == 1);
            }
        }
Ejemplo n.º 15
0
        public void ProcessedStringentPeakEqualsInput()
        {
            // Arrange
            var sA  = new Bed <Peak>();
            var sAP = new Peak(left: 10, right: 20, value: 1e-9);

            sA.Add(sAP, _chr, _strand);

            var sB  = new Bed <Peak>();
            var sBP = new Peak(left: 50, right: 60, value: 1e-12);

            sB.Add(sBP, _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-4, 1e-8, 1e-4, 2, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert

            Assert.True(
                res[0].Chromosomes[_chr].Get(Attributes.Stringent).ToList()[0].Source.Equals(sAP) &&
                res[1].Chromosomes[_chr].Get(Attributes.Stringent).ToList()[0].Source.Equals(sBP));
        }
Ejemplo n.º 16
0
 private bool Run(List <Bed <Peak> > samples, Config config, out Mspc mspc)
 {
     try
     {
         _logger.LogStartOfASection("Analyzing Samples");
         mspc = new Mspc()
         {
             DegreeOfParallelism = _degreeOfParallelism
         };
         mspc.StatusChanged += _logger.LogMSPCStatus;
         foreach (var sample in samples)
         {
             mspc.AddSample(sample.FileHashKey, sample);
         }
         mspc.RunAsync(config);
         mspc.Done.WaitOne();
         return(true);
     }
     catch (Exception e)
     {
         mspc = null;
         _logger.LogException(e);
         Environment.ExitCode = 1;
         return(false);
     }
 }
Ejemplo n.º 17
0
        private ReadOnlyDictionary <uint, Result <Peak> > RunMSPCAndReturnResult(Config config)
        {
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 1E-5), _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 12, right: 18, value: 1E-5), _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            return(mspc.Run(config));
        }
Ejemplo n.º 18
0
        public void FivePeaksThreeOverlapping()
        {
            // Arrange
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 0.01), "chr1", '*');

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 5, right: 18, value: 0.01), "chr1", '*');

            var sC = new Bed <Peak>();

            sC.Add(new Peak(left: 14, right: 25, value: 0.01), "chr1", '*');

            var sD = new Bed <Peak>();

            sD.Add(new Peak(left: 35, right: 40, value: 0.01), "chr1", '*');

            var sE = new Bed <Peak>();

            sE.Add(new Peak(left: 43, right: 50, value: 0.01), "chr1", '*');

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);
            mspc.AddSample(2, sC);
            mspc.AddSample(3, sD);
            mspc.AddSample(4, sE);

            var config = new Config(ReplicateType.Biological, 1, 1, 1, 1, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            var res = mspc.Run(config);

            // Assert
            Assert.True(new[]
            {
                res[0].Chromosomes["chr1"].Get(Attributes.Confirmed).Count(),
                res[1].Chromosomes["chr1"].Get(Attributes.Confirmed).Count(),
                res[2].Chromosomes["chr1"].Get(Attributes.Confirmed).Count(),
                res[3].Chromosomes["chr1"].Get(Attributes.Confirmed).Count(),
                res[4].Chromosomes["chr1"].Get(Attributes.Confirmed).Count()
            }.All(x => x == 1));
        }
Ejemplo n.º 19
0
        private Mspc InitializeMSPC()
        {
            ///                 r11                r12
            /// Sample 0: --░░░░░░░░░░░-------████████████----------------------------
            ///                           r21             r22        r23
            /// Sample 1: ---------████████████████----▒▒▒▒▒▒▒▒---▒▒▒▒▒▒▒▒------------
            ///           r31       r32                                       r33
            /// Sample 2: ▒▒▒▒---██████████---------------------------------████████--
            ///
            /// Legend: [░░ Background peak], [▒▒ Weak peak], [██ Stringent peak]

            var r11 = new Peak(left: 3, right: 13, value: 1e-2, summit: 10, name: "r11");
            var r12 = new Peak(left: 21, right: 32, value: 1e-12, summit: 25, name: "r12");
            var r21 = new Peak(left: 10, right: 25, value: 1e-8, summit: 20, name: "r21");
            var r22 = new Peak(left: 30, right: 37, value: 1e-5, summit: 35, name: "r22");
            var r23 = new Peak(left: 41, right: 48, value: 1e-6, summit: 45, name: "r23");
            var r31 = new Peak(left: 0, right: 4, value: 1e-6, summit: 2, name: "r31");
            var r32 = new Peak(left: 8, right: 17, value: 1e-12, summit: 12, name: "r32");
            var r33 = new Peak(left: 51, right: 58, value: 1e-18, summit: 55, name: "r33");

            var sA = new Bed <Peak>();

            sA.Add(r11, _chr, _strand);
            sA.Add(r12, _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(r21, _chr, _strand);
            sB.Add(r22, _chr, _strand);
            sB.Add(r23, _chr, _strand);

            var sC = new Bed <Peak>();

            sC.Add(r31, _chr, _strand);
            sC.Add(r32, _chr, _strand);
            sC.Add(r33, _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);
            mspc.AddSample(2, sC);

            return(mspc);
        }
Ejemplo n.º 20
0
 internal void Run()
 {
     foreach (var sample in _samples)
     {
         _mspc.AddSample(sample.FileHashKey, sample);
     }
     _mspc.RunAsync(_options);
     _mspc.Done.WaitOne();
 }
Ejemplo n.º 21
0
        public void NumberOfPeaks()
        {
            // Arrange
            var mspc = new Mspc();

            mspc.AddSample(0, CreateSample(0, 20, 1000));
            mspc.AddSample(1, CreateSample(2, 20, 2000));

            // Act
            var res = mspc.Run(new Config(
                                   ReplicateType.Biological, 1e-4, 1e-5, 1e-5, 1, 0.05F, MultipleIntersections.UseLowestPValue));

            // Assert
            for (int c = 0; c < 20; c++)
            {
                Assert.True(res[0].Chromosomes["chr" + c].Get(Attributes.Confirmed).Count() == 1000);
                Assert.True(res[1].Chromosomes["chr" + c].Get(Attributes.Confirmed).Count() == 2000);
            }
        }
Ejemplo n.º 22
0
        private ReadOnlyDictionary <uint, Result <Peak> > GenerateAndProcessStringentPeaks()
        {
            var sA = new Bed <Peak>();

            sA.Add(new Peak(left: 10, right: 20, value: 1e-9), _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: 5, right: 12, value: 1e-12), _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-4, 1e-8, 1e-4, 2, 1F, MultipleIntersections.UseLowestPValue);

            // Act
            return(mspc.Run(config));
        }
Ejemplo n.º 23
0
        private ReadOnlyDictionary <uint, Result <Peak> > InitializeAndRun(MultipleIntersections miChoice)
        {
            // Arrange
            var sA = new Bed <Peak>();

            sA.Add(r11, _chr, _strand);

            var sB = new Bed <Peak>();

            sB.Add(r21, _chr, _strand);
            sB.Add(r22, _chr, _strand);
            sB.Add(r23, _chr, _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            // Act
            return(mspc.Run(new Config(ReplicateType.Biological, 1e-4, 1e-8, 1e-8, 2, 1F, miChoice)));
        }
Ejemplo n.º 24
0
        public void MergeTwoConsensusPeaks(int xLeft, int xRight, int yLeft, int yRight, int cLeft, int cRight)
        {
            // Arrange
            var mspc = new Mspc();
            var sA   = new Bed <Peak>();

            sA.Add(new Peak(left: xLeft, right: xRight, value: 0.01), _chr, _strand);
            mspc.AddSample(0, sA);

            var sB = new Bed <Peak>();

            sB.Add(new Peak(left: yLeft, right: yRight, value: 0.01), _chr, _strand);
            mspc.AddSample(1, sB);

            // Act
            mspc.Run(new Config(ReplicateType.Biological, 1, 1, 1, 1, 1F, MultipleIntersections.UseLowestPValue));
            var cp = mspc.GetConsensusPeaks()[_chr].First();

            // Assert
            Assert.True(cp.Source.Left == cLeft && cp.Source.Right == cRight);
        }
Ejemplo n.º 25
0
        private ReadOnlyDictionary <string, List <ProcessedPeak <Peak> > > GetSampleConsensusPeaks(float alpha = 1e-15F)
        {
            ///                 r11                 r12
            /// Sample 0: ----▓▓▓▓▓▓--------------▓▓▓▓▓▓-----------------------
            ///               r21         r22             r23    r24
            /// Sample 1: --▓▓▓▓▓▓--------▓▓▓-------------░░░---▓▓▓▓▓----------
            ///                 r31                 r32             r33
            /// Sample 2: -▓▓▓▓▓▓▓▓▓▓▓▓-----------▓▓▓▓▓▓----------▓▓▓▓▓▓▓▓-----
            ///
            var s0 = new Bed <Peak>();

            s0.Add(new Peak(10, 20, 1.23E-8), _chrs[0], _strand);
            s0.Add(new Peak(50, 60, 1.56E-80), _chrs[2], _strand);

            var s1 = new Bed <Peak>();

            s1.Add(new Peak(6, 16, 4.56E-8), _chrs[0], _strand);
            s1.Add(new Peak(36, 40, 1.31E-23), _chrs[1], _strand);
            s1.Add(new Peak(64, 68, 1.02E-2), _chrs[3], _strand);
            s1.Add(new Peak(70, 80, 8.76E-9), _chrs[4], _strand);

            var s2 = new Bed <Peak>();

            s2.Add(new Peak(2, 26, 7.89E-10), _chrs[0], _strand);
            s2.Add(new Peak(50, 60, 9.9E-200), _chrs[2], _strand);
            s2.Add(new Peak(76, 90, 1.1E-8), _chrs[4], _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, s0);
            mspc.AddSample(1, s1);
            mspc.AddSample(2, s2);

            mspc.Run(new Config(ReplicateType.Biological, 1E-4, 1E-6, 1E-6, 1, alpha, MultipleIntersections.UseLowestPValue));

            return(mspc.GetConsensusPeaks());
        }
Ejemplo n.º 26
0
        private string RunMSPCAndExportResultsWithMultiChr()
        {
            var s0 = new Bed <Peak>();

            for (int i = 0; i < peaks.Count; i++)
            {
                s0.Add(peaks[i], chrs[i], _strand);
            }

            var s1 = new Bed <Peak>();

            s1.Add(new Peak(800, 900, 1E-2), "chr5", _strand);

            var mspc = new Mspc();

            mspc.AddSample(0, s0);
            mspc.AddSample(1, s1);

            mspc.Run(new Config(ReplicateType.Biological, 1e-4, 1e-5, 1e-5, 1, 0.05F, MultipleIntersections.UseLowestPValue));
            var path = Environment.CurrentDirectory + Path.DirectorySeparatorChar + "MSPCTests_" + new Random().NextDouble().ToString();

            new Exporter <Peak>().Export(_sidfm, mspc.GetResults(), mspc.GetConsensusPeaks(), new Options(path, false, _attributes));
            return(path);
        }
Ejemplo n.º 27
0
        public void RunAsyncIfAtLeastTwoInputIsGiven(int inputCount)
        {
            // Arrange
            var mspc = new Mspc();

            if (inputCount == 1)
            {
                mspc.AddSample(0, new Bed <Peak>());
            }
            var config = new Config(ReplicateType.Biological, 1e-1, 1e-2, 1e-2, 2, 0.05F, MultipleIntersections.UseLowestPValue);

            // Act & Assert
            var exception = Assert.Throws <InvalidOperationException>(() => mspc.RunAsync(config));

            Assert.Equal(string.Format("Minimum two samples are required; {0} is given.", inputCount), exception.Message);
        }
Ejemplo n.º 28
0
        public void AssertCRequirement(int samplesCount, int c, int confirmedPeaksCount, int discardedPeaksCount)
        {
            // Arrange
            uint id   = 0;
            var  mspc = new Mspc();

            foreach (var peak in GetPeaks(samplesCount))
            {
                var sample = new Bed <Peak>();
                sample.Add(peak, _chr, _strand);
                mspc.AddSample(id++, sample);
            }

            // Act
            var res = mspc.Run(new Config(ReplicateType.Biological, 1e-4, 1e-8, 1e-8, c, 1F, MultipleIntersections.UseLowestPValue));

            // Assert
            Assert.True(res[0].Chromosomes[_chr].Get(Attributes.Confirmed).Count() == confirmedPeaksCount);
            Assert.True(res[0].Chromosomes[_chr].Get(Attributes.Discarded).Count() == discardedPeaksCount);
        }
Ejemplo n.º 29
0
        private ReadOnlyDictionary <uint, Result <Peak> > RunThenCancelMSPC(int iCount, Status status)
        {
            var sA = new Bed <Peak>();
            var sB = new Bed <Peak>();

            for (int i = 0; i < iCount; i++)
            {
                sA.Add(new Peak(
                           left: (10 * i) + 1,
                           right: (10 * i) + 4,
                           value: 1E-4,
                           summit: 0,
                           name: "r1" + i),
                       _chr, _strand);

                sB.Add(new Peak(
                           left: (10 * i) + 6,
                           right: (10 * i) + 9,
                           value: 1E-5,
                           summit: 0,
                           name: "r1" + i),
                       _chr, _strand);
            }

            var mspc = new Mspc();

            mspc.AddSample(0, sA);
            mspc.AddSample(1, sB);

            var config = new Config(ReplicateType.Biological, 1e-1, 1e-2, 1e-2, 1, 0.05F, MultipleIntersections.UseLowestPValue);

            switch (status)
            {
            case Status.Init:
                _continueIni = new AutoResetEvent(false);
                _continueIni.Reset();
                mspc.StatusChanged += WaitingIni;
                // MSPC is expected to confirm peaks using the following configuration.
                mspc.RunAsync(config);
                _continueIni.WaitOne();
                break;

            case Status.Process:
                _continuePrc = new AutoResetEvent(false);
                _continuePrc.Reset();
                mspc.StatusChanged += WaitingPrc;
                // MSPC is expected to confirm peaks using the following configuration.
                mspc.RunAsync(config);
                _continuePrc.WaitOne();
                break;

            case Status.MTC:
                _continueMtc = new AutoResetEvent(false);
                _continueMtc.Reset();
                mspc.StatusChanged += WaitingMtc;
                // MSPC is expected to confirm peaks using the following configuration.
                mspc.RunAsync(config);
                _continueMtc.WaitOne();
                break;

            case Status.Consensu:
                _continueCon = new AutoResetEvent(false);
                _continueCon.Reset();
                mspc.StatusChanged += WaitingCon;
                // MSPC is expected to confirm peaks using the following configuration.
                mspc.RunAsync(config);
                _continueCon.WaitOne();
                break;
            }

            // With the following configuration, MSPC discards all the peaks.
            // This can help asserting if the asynchronous process of
            // the previous execution is canceled, and instead the following asynchronous
            // execution is completed.
            mspc.RunAsync(new Config(ReplicateType.Biological, 1e-10, 1e-20, 1e-200, 1, 0.05F, MultipleIntersections.UseLowestPValue));
            mspc.Done.WaitOne();

            return(mspc.GetResults());
        }