private void WriteInfoFile(List <string> result, string resultFilename, ReadSummary readSummary, List <FeatureItemGroup> allmapped)
        {
            var infoFile = Path.ChangeExtension(resultFilename, ".info");

            WriteSummaryFile(infoFile, readSummary, allmapped);
            result.Add(infoFile);
        }
        protected ReadSummary GetReadSummary(List <FeatureItemGroup> allmapped, HashSet <string> excludeQueries, List <SAMAlignedItem> reads, List <QueryInfo> totalQueries)
        {
            var result = new ReadSummary();

            if (File.Exists(options.CountFile))
            {
                result.TotalRead = Counts.GetTotalCount();
            }
            else
            {
                result.TotalRead = totalQueries.Count;
            }

            var featureQueries = new HashSet <string>(from fig in allmapped
                                                      from fi in fig
                                                      from loc in fi.Locations
                                                      from sl in loc.SamLocations
                                                      select sl.SamLocation.Parent.OriginalQname);

            result.FeatureRead = featureQueries.Sum(l => Counts.GetCount(l));

            result.ExcludeRead = excludeQueries.Sum(l => Counts.GetCount(l));

            result.GenomeRead = (from query in totalQueries
                                 where (!query.Name.Contains(SmallRNAConsts.NTA_TAG) || query.Name.EndsWith(SmallRNAConsts.NTA_TAG))
                                 let originalQname = query.Name.StringBefore(SmallRNAConsts.NTA_TAG)
                                                     where !featureQueries.Contains(originalQname) && query.Mismatch == 0 && query.Length >= options.TooShortReadLength
                                                     select originalQname).Distinct().Sum(m => Counts.GetCount(m));

            if (Counts.ItemMap != null)
            {
                result.TooShortRead = (from read in Counts.ItemMap.Values
                                       where !featureQueries.Contains(read.Qname) && read.SequenceLength < 20
                                       select read.Count).Sum();
            }
            else
            {
                result.TooShortRead = 0;
            }

            return(result);
        }
        protected void WriteSummaryFile(string infoFile, ReadSummary readSummary, List <FeatureItemGroup> allmapped)
        {
            if (!File.Exists(infoFile) || !options.NotOverwrite)
            {
                Progress.SetMessage("summarizing ...");
                using (var sw = new StreamWriter(infoFile))
                {
                    WriteOptions(sw);

                    if (File.Exists(options.CountFile))
                    {
                        sw.WriteLine("#countFile\t{0}", options.CountFile);
                    }

                    sw.WriteLine("TotalReads\t{0}", readSummary.TotalRead);
                    if (readSummary.ExcludeRead > 0)
                    {
                        sw.WriteLine("ExcludedReads\t{0}", readSummary.ExcludeRead);
                    }
                    sw.WriteLine("MappedReads\t{0}", readSummary.MappedRead);
                    sw.WriteLine("FeatureReads\t{0}", readSummary.FeatureRead);
                    sw.WriteLine("GenomeReads\t{0}", readSummary.GenomeRead);
                    sw.WriteLine("TooShortReads\t{0}", readSummary.TooShortRead);
                    sw.WriteLine("UnannotatedReads\t{0}", readSummary.UnannotatedRead);

                    //Output individual category
                    foreach (var cat in SmallRNAConsts.Biotypes)
                    {
                        var count = (from c in allmapped
                                     from l in c
                                     where l.Name.StartsWith(cat)
                                     select l.GetEstimatedCount()).Sum();
                        if (count > 0)
                        {
                            sw.WriteLine("{0}\t{1:0.#}", cat, count);
                        }
                    }
                }
            }
        }