Exemple #1
0
        public virtual IEnumerable <string> WriteToFile(string outputFile, List <FeatureItemGroup> features, string removeNamePrefix)
        {
            Dictionary <string, Dictionary <string, SmallRNASequence> > sequences = new Dictionary <string, Dictionary <string, SmallRNASequence> >();

            foreach (var fig in features)
            {
                foreach (var sam in fig)
                {
                    foreach (var loc in sam.Locations)
                    {
                        foreach (var samloc in loc.SamLocations)
                        {
                            var aligned = samloc.SamLocation.Parent;
                            var seq     = new SmallRNASequence()
                            {
                                Sample   = aligned.Sample,
                                Sequence = aligned.Sequence,
                                Count    = aligned.QueryCount
                            };

                            Dictionary <string, SmallRNASequence> ssList;
                            if (!sequences.TryGetValue(seq.Sample, out ssList))
                            {
                                ssList = new Dictionary <string, SmallRNASequence>();
                                sequences[seq.Sample] = ssList;
                                ssList[seq.Sequence]  = seq;
                            }
                            else
                            {
                                if (!ssList.ContainsKey(seq.Sequence))
                                {
                                    ssList[seq.Sequence] = seq;
                                }
                            }
                        }
                    }
                }
            }

            var counts  = sequences.ToDictionary(m => m.Key, m => m.Value.Values.ToList());
            var samples = sequences.Keys.OrderBy(m => m).ToArray();

            List <SmallRNASequenceContig> mergedSequences = SmallRNASequenceUtils.BuildContigByIdenticalSimilarity(counts, minOverlapRate, maxExtensionBase, topNumber);

            new SmallRNASequenceContigFormat().WriteToFile(outputFile, mergedSequences);
            new SmallRNASequenceContigDetailFormat().WriteToFile(outputFile + ".details", mergedSequences);

            return(new[] { outputFile });
        }
Exemple #2
0
        private void OutputGroup(List <string> result, Dictionary <string, List <SmallRNASequence> > counts, string[] samples)
        {
            var outputFile = options.OutputFile;

            Progress.SetMessage("Building sequence contig...");
            var mergedSequences = SmallRNASequenceUtils.BuildContigByIdenticalSimilarity(counts, options.MinimumOverlapRate, options.MaximumExtensionBase, options.TopNumber);

            Progress.SetMessage("Saving sequence contig...");
            new SmallRNASequenceContigFormat().WriteToFile(options.OutputFile, mergedSequences);
            result.Add(options.OutputFile);

            if (options.ExportContigDetails)
            {
                Progress.SetMessage("Saving sequence contig details...");
                new SmallRNASequenceContigDetailFormat().WriteToFile(options.OutputFile + ".details", mergedSequences);
                result.Add(options.OutputFile + ".details");
            }

            var miniContigFile = Path.ChangeExtension(options.OutputFile, ".minicontig.count");

            Progress.SetMessage("Saving mini sequence contig...");
            var miniContig = SmallRNASequenceUtils.BuildMiniContig(mergedSequences, options.TopNumber);

            new SmallRNASequenceContigFormat().WriteToFile(miniContigFile, miniContig);
            result.Add(miniContigFile);

            if (options.ExportContigDetails)
            {
                Progress.SetMessage("Saving mini sequence contig details...");
                new SmallRNASequenceContigDetailFormat().WriteToFile(miniContigFile + ".details", miniContig);
                result.Add(miniContigFile + ".details");
            }

            if (options.ExportFasta)
            {
                var fastaFile = options.OutputFile + ".fasta";
                Progress.SetMessage("Saving " + fastaFile + " ...");
                new SmallRNASequenceContigFastaFormat(options.TopNumber).WriteToFile(fastaFile, mergedSequences);
                result.Add(fastaFile);

                var miniContigFastaFile = miniContigFile + ".fasta";
                Progress.SetMessage("Saving " + miniContigFastaFile + " ...");
                new SmallRNASequenceContigFastaFormat(options.TopNumber).WriteToFile(miniContigFastaFile, miniContig);
                result.Add(miniContigFastaFile);
            }
        }