public void TestReadFromFileWithoutFilter()
    {
      var data = new MpileupFisherResultFileFormat().ReadFromFile(@"../../../data/TCGA-BH-A0E0-DNA-TP-NB.candidates");
      Assert.AreEqual(850, data.Count);

      var res = data[0];
      Assert.AreEqual("1", res.Item.SequenceIdentifier);
      Assert.AreEqual(5732744, res.Item.Position);
      Assert.AreEqual('G', res.Item.Nucleotide);
      Assert.AreEqual("G", res.Group.SucceedName);
      Assert.AreEqual("T", res.Group.FailedName);
      Assert.AreEqual(44, res.Group.Sample1.Succeed);
      Assert.AreEqual(1, res.Group.Sample1.Failed);
      Assert.AreEqual(11, res.Group.Sample2.Succeed);
      Assert.AreEqual(3, res.Group.Sample2.Failed);
      Assert.AreEqual(3.8E-02, res.Group.PValue, 0.01);
    }
    public void TestReadFromFileWithFilter()
    {
      var data = new MpileupFisherResultFileFormat().ReadFromFile(@"../../../data/glmvc.candidates");
      Assert.AreEqual(24, data.Count);

      var res = data[3];
      Assert.AreEqual("2", res.Item.SequenceIdentifier);
      Assert.AreEqual(110301779, res.Item.Position);
      Assert.AreEqual('A', res.Item.Nucleotide);
      Assert.AreEqual("A", res.Group.SucceedName);
      Assert.AreEqual("", res.Group.FailedName);
      Assert.AreEqual(23, res.Group.Sample1.Succeed);
      Assert.AreEqual(0, res.Group.Sample1.Failed);
      Assert.AreEqual(9, res.Group.Sample2.Succeed);
      Assert.AreEqual(0, res.Group.Sample2.Failed);
      Assert.AreEqual(1.0E00, res.Group.PValue, 0.01);
      Assert.AreEqual("Read depth < 10", res.FailedReason);
    }
Example #3
0
    public override IEnumerable<string> Process()
    {
      if (!File.Exists(_options.BaseFilename) || new FileInfo(_options.BaseFilename).Length == 0)
      {
        base.Process();
      }
      else
      {
        Progress.SetMessage("Base file {0} exists, ignore pileup ...", _options.BaseFilename);
      }

      var filterOptions = options.GetFilterOptions();

      if (new FileInfo(_options.BaseFilename).Length > 0)
      {
        if (!filterOptions.PrepareOptions())
        {
          throw new Exception("Filter options failed: " + filterOptions.ParsingErrors.Merge("\n"));
        }

        new FilterProcessor(filterOptions).Process();

        var lines = File.ReadAllLines(filterOptions.ROutputFile).Skip(1).ToArray();
        var glmfailed = lines.Count(m => m.Contains("GLM_PVALUE"));
        var summarylines = File.ReadAllLines(_options.SummaryFilename).ToList();
        if (summarylines.Last().StartsWith("glm pvalue"))
        {
          summarylines.RemoveAt(summarylines.Count - 1);
        }
        summarylines.Add(string.Format("glm pvalue > {0}\t{1}\t{2}", options.GlmPvalue, glmfailed, lines.Length - glmfailed));
        File.WriteAllLines(_options.SummaryFilename, summarylines);
      }

      var mutationList = GetValidationList();
      var candidates = new MpileupFisherResultFileFormat().ReadFromFile(options.CandidatesFilename).ToDictionary(m => GenomeUtils.GetKey(m.Item.SequenceIdentifier, m.Item.Position));
      var items = new FilterItemTextFormat().ReadFromFile(filterOptions.ROutputFile).ToDictionary(m => GenomeUtils.GetKey(m.Chr, m.Start));

      var result = new List<FilterItem>();
      foreach (var mutation in mutationList.Items)
      {
        var key = GenomeUtils.GetKey(mutation.Chr, mutation.Pos);
        if (items.ContainsKey(key))
        {
          result.Add(items[key]);
        }
        else
        {
          var item = new FilterItem();
          item.Chr = mutation.Chr;
          item.Start = mutation.Pos;
          item.End = item.Start;
          item.FisherNormal = string.Empty;
          item.BrglmConverged = string.Empty;
          item.BrglmGroup = 1.0;
          item.BrglmGroupFdr = 1.0;
          item.BrglmScore = string.Empty;
          item.BrglmStrand = string.Empty;
          item.BrglmPosition = string.Empty;
          item.Identity = string.Empty;
          result.Add(item);

          if (candidates.ContainsKey(key))
          {
            var cand = candidates[key];
            item.ReferenceAllele = cand.Item.Nucleotide.ToString();
            item.MajorAllele = cand.Group.SucceedName;
            item.MinorAllele = cand.Group.FailedName;
            item.NormalMajorCount = cand.Group.Sample1.Succeed;
            item.NormalMinorCount = cand.Group.Sample1.Failed;
            item.TumorMajorCount = cand.Group.Sample2.Succeed;
            item.TumorMinorCount = cand.Group.Sample2.Failed;
            item.FisherGroup = cand.Group.PValue;
            item.Filter = cand.FailedReason;
            Console.WriteLine("In candidates : " + item.Filter);
          }
          else
          {
            item.NormalMajorCount = 0;
            item.NormalMinorCount = 0;
            item.TumorMajorCount = 0;
            item.TumorMinorCount = 0;
            item.Filter = "No coverage";
            Console.WriteLine("No read : " + item.Filter);
          }
        }
      }

      new FilterItemVcfWriter(filterOptions).WriteToFile(_options.OutputSuffix + ".vcf", result);
      new FilterItemTextFormat().WriteToFile(_options.OutputSuffix + ".tsv", result);

      return new string[] { _options.OutputSuffix + ".tsv", _options.OutputSuffix + ".vcf" };
    }