Exemplo n.º 1
0
    public override IEnumerable<string> Process()
    {
      var bamList = ReadBamList();

      var process = ExecuteSamtools(bamList);
      if (process == null)
      {
        throw new Exception("Fail to execute samtools.");
      }

      var vcfItems = new VcfItemListFormat().ReadFromFile(_options.InputFile);
      vcfItems.Header = vcfItems.Header + "\t" + bamList.ConvertAll(m => m.Value).Merge("\t");

      var vcfMap = vcfItems.Items.ToDictionary(m => GetKey(m.Seqname, m.Start));

      var parser = _options.GetPileupItemParser();
      var pfile = new PileupFile(parser);
      pfile.Open(process.StandardOutput);

      try
      {
        using (pfile)
        {
          string line;
          while ((line = pfile.ReadLine()) != null)
          {
            var item = parser.GetSequenceIdentifierAndPosition(line);
            var key = GetKey(item.SequenceIdentifier, item.Position);

            VcfItem vcf;
            if (!vcfMap.TryGetValue(key, out vcf))
            {
              continue;
            }

            item = parser.GetValue(line);
            foreach (var sample in item.Samples)
            {
              var refCount = sample.Count(m => m.Event.Equals(vcf.RefAllele));
              var altCount = sample.Count(m => m.Event.Equals(vcf.AltAllele));
              vcf.Line = vcf.Line + string.Format("\t{0}:{1}", refCount, altCount);
            }
          }
        }
      }
      finally
      {
        try
        {
          if (process != null) process.Kill();
        }
        catch
        { }
      }

      new VcfItemListFormat().WriteToFile(_options.OutputFile, vcfItems);

      return new string[] { _options.OutputFile };
    }
Exemplo n.º 2
0
        public override IEnumerable <string> Process()
        {
            var bamList = ReadBamList();

            var process = ExecuteSamtools(bamList);

            if (process == null)
            {
                throw new Exception("Fail to execute samtools.");
            }

            var vcfItems = new VcfItemListFormat().ReadFromFile(_options.InputFile);

            vcfItems.Header = vcfItems.Header + "\t" + bamList.ConvertAll(m => m.Value).Merge("\t");

            var vcfMap = vcfItems.Items.ToDictionary(m => GetKey(m.Seqname, m.Start));

            var parser = _options.GetPileupItemParser();
            var pfile  = new PileupFile(parser);

            pfile.Open(process.StandardOutput);

            try
            {
                using (pfile)
                {
                    string line;
                    while ((line = pfile.ReadLine()) != null)
                    {
                        var item = parser.GetSequenceIdentifierAndPosition(line);
                        var key  = GetKey(item.SequenceIdentifier, item.Position);

                        VcfItem vcf;
                        if (!vcfMap.TryGetValue(key, out vcf))
                        {
                            continue;
                        }

                        item = parser.GetValue(line);
                        foreach (var sample in item.Samples)
                        {
                            var refCount = sample.Count(m => m.Event.Equals(vcf.RefAllele));
                            var altCount = sample.Count(m => m.Event.Equals(vcf.AltAllele));
                            vcf.Line = vcf.Line + string.Format("\t{0}:{1}", refCount, altCount);
                        }
                    }
                }
            }
            finally
            {
                try
                {
                    if (process != null)
                    {
                        process.Kill();
                    }
                }
                catch
                { }
            }

            new VcfItemListFormat().WriteToFile(_options.OutputFile, vcfItems);

            return(new string[] { _options.OutputFile });
        }