Exemplo n.º 1
0
        public Genome(
            string workingDirectory,
            string sectionTitle,
            Memory memory,
            HDDPerformance hddPerformance,
            CacheOptions cacheOptions,
            ISerializer <C> CSerializer,
            IComparer <C> CComparer)
        {
            _memory         = memory;
            _hddPerformance = hddPerformance;
            _CSerializer    = CSerializer;
            _CComparer      = CComparer;
            _sectionTitle   = sectionTitle;
            _cacheOptions   = cacheOptions;
            _stpWtch        = new Stopwatch();

            _config   = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            _settings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings;

            if (_memory == Memory.RAM)
            {
                chrs = new Dictionary <string, Dictionary <char, Di4 <C, I, M> > >();
            }
            else if (_memory == Memory.HDD && _hddPerformance == HDDPerformance.Fastest)
            {
                chrs = new Dictionary <string, Dictionary <char, Di4 <C, I, M> > >();

                _chrSection = (ChrSection)ConfigurationManager.GetSection(_sectionTitle);
                if (_chrSection == null)
                {
                    _chrSection = new ChrSection();
                }
                ConfigurationManager.RefreshSection(_sectionTitle);

                foreach (ChrConfigElement element in _chrSection.genomeChrs)
                {
                    if (!chrs.ContainsKey(element.chr))
                    {
                        chrs.Add(element.chr, new Dictionary <char, Di4 <C, I, M> >());
                    }

                    if (!chrs[element.chr].ContainsKey(element.strand))
                    {
                        chrs[element.chr].Add(element.strand, new Di4 <C, I, M>(GetDi4Options(element.index)));
                    }
                }
            }
        }
Exemplo n.º 2
0
        internal ExecutionReport Add(
            uint collectionID,
            Dictionary <string, Dictionary <char, List <I> > > intervals,
            char strand,
            IndexingMode indexinMode,
            MaxDegreeOfParallelism maxDegreeOfParallelism)
        {
            int totalIntervals = 0;

            switch (_memory)
            {
            case Memory.HDD:
                if (_chrSection == null)
                {
                    _chrSection = new ChrSection();
                }
                ConfigurationManager.RefreshSection(_sectionTitle);

                switch (_hddPerformance)
                {
                // TODO:
                // This case is not complete, because other operations
                // are not supporting this method.
                case HDDPerformance.LeastMemory:
                    _stpWtch.Restart();
                    foreach (var chr in intervals)
                    {
                        foreach (var strandEntry in chr.Value)
                        {
                            using (var di4 = new Di4 <C, I, M>(GetDi4Options(GetDi4File(chr.Key, strand))))        // this might be wrong
                            {
                                di4.Add(strandEntry.Value, indexinMode, collectionID, maxDegreeOfParallelism.di4Degree);
                                totalIntervals += strandEntry.Value.Count;
                            }
                        }
                    }
                    _stpWtch.Stop();
                    break;

                case HDDPerformance.Fastest:
                    /// Initialize by a sequential foreach loop.
                    foreach (var chr in intervals)
                    {
                        foreach (var strandEntry in chr.Value)
                        {
                            if (!chrs.ContainsKey(chr.Key))
                            {
                                chrs.Add(chr.Key, new Dictionary <char, Di4 <C, I, M> >());
                            }
                            if (!chrs[chr.Key].ContainsKey(strand))
                            {
                                chrs[chr.Key].Add(strand, new Di4 <C, I, M>(GetDi4Options(GetDi4File(chr.Key, strand))));
                            }
                        }
                    }

                    _stpWtch.Restart();
                    /// Populate inside a parallel foreach loop.
                    Parallel.ForEach(intervals,
                                     new ParallelOptions {
                        MaxDegreeOfParallelism = maxDegreeOfParallelism.chrDegree
                    },
                                     chr =>
                    {
                        foreach (var strandEntry in chr.Value)
                        {
                            chrs[chr.Key][strand].Add(strandEntry.Value, indexinMode, collectionID, maxDegreeOfParallelism.di4Degree);
                            //chrs[chr.Key][strand].Commit();
                            totalIntervals += strandEntry.Value.Count;
                        }
                    });
                    _stpWtch.Stop();
                    break;
                }


                if (_config.Sections[_sectionTitle] == null)
                {
                    _config.Sections.Add(_sectionTitle, _chrSection);
                }

                _config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection(_sectionTitle);
                break;

            case Memory.RAM:
                _stpWtch.Restart();
                foreach (var chr in intervals)
                {
                    foreach (var strandEntry in chr.Value)
                    {
                        if (!chrs.ContainsKey(chr.Key))
                        {
                            chrs.Add(chr.Key, new Dictionary <char, Di4 <C, I, M> >());
                        }
                        if (!chrs[chr.Key].ContainsKey(strand))
                        {
                            chrs[chr.Key].Add(strand, new Di4 <C, I, M>(GetDi4Options()));
                        }

                        chrs[chr.Key][strand].Add(strandEntry.Value, indexinMode, collectionID, maxDegreeOfParallelism.di4Degree);
                        totalIntervals += strandEntry.Value.Count;
                    }
                }
                _stpWtch.Stop();
                break;
            }

            return(new ExecutionReport(totalIntervals, _stpWtch.Elapsed));
        }