Esempio n. 1
0
        public static List <SmallRNASequence> ReadCountFile(FileItem file, Func <string[], bool> accept)
        {
            var countList = new List <SmallRNASequence>();

            using (var sr = new StreamReader(file.File))
            {
                var    header = sr.ReadLine();
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    var parts = line.Split('\t');
                    if (parts.Length < 3)
                    {
                        continue;
                    }
                    if (!accept(parts))
                    {
                        continue;
                    }

                    var seq = new SmallRNASequence()
                    {
                        Sample   = file.Name,
                        Sequence = parts[2],
                        Count    = int.Parse(parts[1])
                    };

                    countList.Add(seq);
                }
            }

            return(countList);
        }
Esempio n. 2
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 });
        }