public override IEnumerable<string> Process() { var data = new CnMOPsItemReader().ReadFromFile(options.InputFile); Dictionary<string, List<ItemRange>> result = MergeRange(data); var seqnames = result.Keys.OrderBy(m => m).ToList(); GenomeUtils.SortChromosome(seqnames, l => l, l => 1); using (var sw = new StreamWriter(options.OutputFile)) { sw.WriteLine("seqname\tstart\tend\tlocus\tsample\tsample_start\tsample_end\tsample_type"); foreach (var seqname in seqnames) { var ranges = result[seqname]; foreach (var range in ranges) { foreach (var cn in range.Items) { if (options.IgnoreCN1CN3 && (cn.CN.Equals("CN1") || cn.CN.Equals("CN3"))) { continue; } sw.WriteLine("{0}\t{1}\t{2}\t{0}:{1}-{2}\t{3}\t{4}\t{5}\t{6}", seqname, range.Start, range.End, cn.FileName, cn.Start, cn.End, cn.CN); } } } } var filenames = (from d in data select d.FileName).Distinct().OrderBy(l => l).ToArray(); using (var sw = new StreamWriter(options.OutputFile + ".cnvr")) { sw.WriteLine("seqname\tstart\tend\tfile\t{0}", filenames.Merge("\t")); foreach (var seqname in seqnames) { var ranges = result[seqname]; foreach (var range in ranges) { var cns = (from filename in filenames let cn = range.Items.Where(l => l.FileName.Equals(filename)).FirstOrDefault() select cn == null ? "CN2" : cn.CN).ToArray(); if (options.IgnoreCN1CN3 && cns.All(l => l.Equals("CN1") || l.Equals("CN2") || l.Equals("CN3"))) { continue; } sw.WriteLine("{0}\t{1}\t{2}\t{0}_{1}_{2}\t{3}", seqname, range.Start, range.End, cns.Merge("\t")); } } } return new[] { options.OutputFile, options.OutputFile + ".cnvr" }; }
public void Test() { var data = new CnMOPsItemReader().ReadFromFile("../../../data/cnmops.txt"); var focus_before = data.Where(l => l.Start > 3000000 && l.End < 9000000).ToList(); var ranges = CnMOPSCallProcessor.MergeRange(focus_before); var focus = ranges["5"]; Assert.AreEqual(1, focus.Count); Assert.AreEqual(3000100, focus[0].Start); Assert.AreEqual(8494963, focus[0].End); //focus.ForEach(l => //{ // Console.WriteLine("{0}-{1}", l.Start, l.End); // l.Items.ForEach(m => // { // Console.WriteLine("\t{0}-{1}\t{2}\t{3}", m.Start, m.End, m.FileName, m.CN); // }); //}); }