public override IEnumerable <string> Process(string useless)
        {
            var result = new MappedMirnaGroupXmlFileFormat().ReadFromFile(options.InputFile);

            using (StreamWriter sw = new StreamWriter(options.OutputFile))
            {
                sw.WriteLine("miRNA\tLocation\tTotalCount\tPerfectMatch\tMiss5_2\tMiss3_3\tMissInternal");
                foreach (var res in result)
                {
                    var items = res.GetAlignedLocations();

                    if (res.DisplayName.Equals("hsa-mir-486-5p:TCCTGTACTGAGCTGCCCCGAG"))
                    {
                        items.ForEach(m => Console.WriteLine(m.Parent.Qname + "\t" + m.Strand + "\t" + m.MismatchPositions));
                    }
                    var pmcount = items.Count(m => m.NumberOfMismatch == 0);
                    var mis5    = items.Count(m =>
                    {
                        SAMAlignedLocation loc = m;

                        if (loc.NumberOfMismatch == 0)
                        {
                            return(false);
                        }

                        var mp = loc.MismatchPositions;
                        if (loc.Strand == '-')
                        {
                            mp = new string(mp.Reverse().ToArray());
                        }

                        return(reg5.Match(mp).Success);
                    });

                    var mis3 = items.Count(m =>
                    {
                        var loc = m;
                        if (loc.NumberOfMismatch == 0)
                        {
                            return(false);
                        }

                        var mp = loc.MismatchPositions;
                        if (loc.Strand == '+')
                        {
                            mp = new string(mp.Reverse().ToArray());
                        }

                        return(reg3.Match(mp).Success);
                    });
                    sw.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", res.DisplayName, res.DisplayLocation, items.Count, pmcount, mis5, mis3, items.Count - pmcount - mis5 - mis3);
                }
            }
            return(new string[] { options.OutputFile });
        }
        public override IEnumerable <string> Process()
        {
            var countfiles = options.GetCountFiles();

            var dic = new Dictionary <string, Dictionary <string, MappedMirnaGroup> >();

            foreach (var file in countfiles)
            {
                Progress.SetMessage("Reading miRNA mapped file " + file.File + " ...");
                var mirnas = new MappedMirnaGroupXmlFileFormat().ReadFromFile(file.File);
                dic[file.Name] = mirnas.ToDictionary(m => m.DisplayName);
            }

            var features = (from c in dic.Values
                            from k in c.Keys
                            select k).Distinct().OrderBy(m => m).ToList();

            var names = dic.Keys.OrderBy(m => m).ToList();

            using (StreamWriter sw = new StreamWriter(options.OutputFile))
                using (StreamWriter swNTA = new StreamWriter(options.NTAFile))
                    using (StreamWriter swIso = new StreamWriter(options.IsomirFile))
                        using (StreamWriter swIsoNTA = new StreamWriter(options.IsomirNTAFile))
                        {
                            sw.WriteLine("Feature\tLocation\tSequence\t{0}", names.Merge("\t"));

                            swNTA.WriteLine("Feature\tLocation\tSequence\t{0}", names.Merge("\t"));

                            swIso.WriteLine("Feature\tLocation\tSequence\t{0}", names.Merge("\t"));

                            swIsoNTA.WriteLine("Feature\tLocation\tSequence\t{0}", names.Merge("\t"));

                            foreach (var feature in features)
                            {
                                OutputCount(sw, dic, feature, names, MirnaConsts.NO_OFFSET, false, "");

                                OutputCount(swNTA, dic, feature, names, MirnaConsts.NO_OFFSET, true, "");

                                OutputCount(swIso, dic, feature, names, 0, false, "_+_0");
                                OutputCount(swIso, dic, feature, names, 1, false, "_+_1");
                                OutputCount(swIso, dic, feature, names, 2, false, "_+_2");

                                OutputCount(swIsoNTA, dic, feature, names, 0, true, "_+_0");
                                OutputCount(swIsoNTA, dic, feature, names, 1, true, "_+_1");
                                OutputCount(swIsoNTA, dic, feature, names, 2, true, "_+_2");
                            }
                        }

            var result = new[] { options.OutputFile, options.IsomirFile, options.NTAFile, options.IsomirNTAFile }.ToList();

            return(result);
        }
        public List <MappedMirnaGroup> Build(string countXmlFile)
        {
            var result = new MappedMirnaGroupXmlFileFormat().ReadFromFile(countXmlFile);

            foreach (var group in result)
            {
                foreach (var mirna in group)
                {
                    foreach (var region in mirna.MappedRegions)
                    {
                        var positions = region.Mapped.Keys.ToList();
                        foreach (var position in positions)
                        {
                            var mapped = region.Mapped[position];
                            mapped.AlignedLocations.RemoveAll(q =>
                            {
                                var snp = q.GetNotGsnapMismatch(q.Parent.Sequence);
                                if (null == snp)
                                {
                                    return(true);
                                }

                                return(!snp.IsMutation('T', 'C'));
                            });

                            if (mapped.AlignedLocations.Count == 0)
                            {
                                region.Mapped.Remove(position);
                            }
                        }
                    }

                    mirna.MappedRegions.RemoveAll(l => l.Mapped.Count == 0);
                }

                group.RemoveAll(n => n.MappedRegions.Count == 0);
            }

            result.RemoveAll(m => m.Count == 0);

            return(result);
        }
Пример #4
0
        public override IEnumerable <string> Process()
        {
            var format = new MappedMirnaGroupXmlFileFormat();

            Progress.SetMessage("reading mapped reads from " + options.ReferenceFile + " ...");
            var refitems   = format.ReadFromFile(options.ReferenceFile);
            var refSpecies = refitems[0][0].Name.StringBefore("-");

            Progress.SetMessage("reading mapped reads from " + options.SampleFile + " ...");
            var samitems   = format.ReadFromFile(options.SampleFile);
            var samSpecies = samitems[0][0].Name.StringBefore("-");

            var paired = GetPairedMiRNA(refitems, samitems);

            //using (StreamWriter sw = new StreamWriter(targetFile))
            //{
            //  sw.WriteLine("microRNA\t{0}_sequence\t{1}_sequence\tbp_difference\tquery_sequence\t{0}_count\t{0}_estimate_count\t{1}_count\t{1}_estimate_count", refName, samName);



            //  var keys = refitems.Keys.Union(samitems.Keys).Distinct().OrderBy(m => m).ToList();
            //  foreach (var key in keys)
            //  {
            //    sw.Write(key);
            //    string refseq = string.Empty;
            //    string samseq = string.Empty;
            //    MappedMiRNA refmirna = null;
            //    MappedMiRNA sammirna = null;
            //    Dictionary<string, List<QueryMapped>> refmirnamap = new Dictionary<string, List<QueryMapped>>();
            //    Dictionary<string, List<QueryMapped>> sammirnamap = new Dictionary<string, List<QueryMapped>>();

            //    if (refitems.ContainsKey(key))
            //    {
            //      refmirna = refitems[key];
            //      refseq = refmirna.Name.Contains(":") ? refmirna.Name.StringAfter(":") : string.Empty;
            //      refmirnamap = ConvertToMap(refmirna);
            //    }

            //    if (samitems.ContainsKey(key))
            //    {
            //      sammirna = samitems[key];
            //      samseq = sammirna.Name.Contains(":") ? sammirna.Name.StringAfter(":") : string.Empty;
            //      sammirnamap = ConvertToMap(sammirna);
            //    }

            //    var seqs = refmirnamap.Keys.Union(sammirnamap.Keys).OrderBy(m => m).ToList();

            //    CombinedSequence cs = null;
            //    if (!string.IsNullOrEmpty(refseq) && !string.IsNullOrEmpty(samseq))
            //    {
            //      cs = MirnaUtils.GetCombinedSequence(refseq, samseq);
            //      sw.Write("\t{0}\t{1}\t{2}", cs.GetAnnotatedSequence1(), cs.GetAnnotatedSequence2(), cs.MismatchPositions.Length);
            //    }
            //    else
            //    {
            //      sw.Write("\t{0}\t{1}\t-", refseq, samseq);
            //    }
            //    sw.WriteLine();

            //    foreach (var seq in seqs)
            //    {
            //      sw.Write("\t\t\t\t{0}", seq);
            //      if (refmirnamap.ContainsKey(seq))
            //      {
            //        sw.Write("\t{0:0.00}", refmirnamap[seq].Sum(m => m.QueryCount));
            //        sw.Write("\t{0:0.00}", refmirnamap[seq].Sum(m => m.EsminatedCount));
            //      }
            //      else
            //      {
            //        sw.Write("\t\t");
            //      }

            //      if (sammirnamap.ContainsKey(seq))
            //      {
            //        sw.Write("\t{0:0.00}", sammirnamap[seq].Sum(m => m.QueryCount));
            //        sw.Write("\t{0:0.00}", sammirnamap[seq].Sum(m => m.EsminatedCount));
            //      }
            //      else
            //      {
            //        sw.Write("\t\t");
            //      }
            //      sw.WriteLine();
            //    }
            //  }
            //}

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