Пример #1
0
        /// <summary>
        /// Fills subsequences calculation data dictionary.
        /// </summary>
        /// <param name="minSelectedMatters">
        /// The minimum Selected Matters.
        /// </param>
        /// <param name="maxSelectedMatters">
        /// The maximum Selected Matters.
        /// </param>
        /// <param name="submitName">
        /// The submit button name.
        /// </param>
        /// <returns>
        /// The <see cref="Dictionary{String, Object}"/>.
        /// </returns>
        public Dictionary <string, object> FillSubsequencesViewData(int minSelectedMatters, int maxSelectedMatters, string submitName)
        {
            var sequenceIds = db.Subsequence.Select(s => s.SequenceId).Distinct();
            var matterIds   = db.DnaSequence.Where(c => sequenceIds.Contains(c.Id)).Select(c => c.MatterId).ToList();

            Dictionary <string, object> data = GetMattersData(minSelectedMatters, maxSelectedMatters, m => matterIds.Contains(m.Id));

            var geneticNotations = EnumExtensions.ToArray <Notation>().Where(n => n.GetNature() == Nature.Genetic);
            var sequenceTypes    = EnumExtensions.ToArray <SequenceType>().Where(st => st.GetNature() == Nature.Genetic);
            var groups           = EnumExtensions.ToArray <Group>().Where(g => g.GetNature() == Nature.Genetic);
            var features         = EnumExtensions.ToArray <Feature>().Where(f => f.GetNature() == Nature.Genetic).ToArray();
            var selectedFeatures = features.Where(f => f != Feature.NonCodingSequence);
            Dictionary <string, object> characteristicsData = GetCharacteristicsData(CharacteristicCategory.Full);

            foreach ((string key, object value) in characteristicsData)
            {
                data.Add(key, value);
            }

            data.Add("submitName", submitName);
            data.Add("notations", geneticNotations.ToSelectListWithNature());
            data.Add("nature", ((byte)Nature.Genetic).ToString());
            data.Add("features", features.ToSelectListWithNature(selectedFeatures));
            data.Add("sequenceTypes", sequenceTypes.ToSelectListWithNature(true));
            data.Add("groups", groups.ToSelectListWithNature(true));

            return(data);
        }
Пример #2
0
        /// <summary>
        /// Fills view data.
        /// </summary>
        /// <param name="minSelectedMatters">
        /// The minimum selected matters.
        /// </param>
        /// <param name="maxSelectedMatters">
        /// The maximum selected matters.
        /// </param>
        /// <returns>
        /// The <see cref="Dictionary{String, Object}"/>.
        /// </returns>
        public Dictionary <string, object> FillViewData(int minSelectedMatters, int maxSelectedMatters)
        {
            Dictionary <string, object> data = GetMattersData(minSelectedMatters, maxSelectedMatters, m => true);

            IEnumerable <SelectListItem> natures;
            IEnumerable <SequenceType>   sequenceTypes;
            IEnumerable <Group>          groups;

            if (AccountHelper.IsAdmin())
            {
                natures       = EnumHelper.GetSelectList(typeof(Nature));
                sequenceTypes = EnumExtensions.ToArray <SequenceType>();
                groups        = EnumExtensions.ToArray <Group>();
            }
            else
            {
                natures       = new[] { Nature.Genetic }.ToSelectList();
                sequenceTypes = EnumExtensions.ToArray <SequenceType>().Where(st => st.GetNature() == Nature.Genetic);
                groups        = EnumExtensions.ToArray <Group>().Where(g => g.GetNature() == Nature.Genetic);
            }

            data.Add("natures", natures);
            data.Add("sequenceTypes", sequenceTypes.ToSelectListWithNature(true));
            data.Add("groups", groups.ToSelectListWithNature(true));

            return(data);
        }
Пример #3
0
        /// <summary>
        /// Fills matter creation data.
        /// </summary>
        /// <returns>
        /// The <see cref="Dictionary{String, Object}"/>.
        /// </returns>
        public Dictionary <string, object> FillMatterCreationData()
        {
            IEnumerable <SelectListItem> natures;
            IEnumerable <Notation>       notations;

            IEnumerable <RemoteDb>     remoteDbs     = EnumExtensions.ToArray <RemoteDb>();
            IEnumerable <SequenceType> sequenceTypes = EnumExtensions.ToArray <SequenceType>();
            IEnumerable <Group>        groups        = EnumExtensions.ToArray <Group>();

            if (AccountHelper.IsAdmin())
            {
                natures   = EnumHelper.GetSelectList(typeof(Nature));
                notations = EnumExtensions.ToArray <Notation>();
            }
            else
            {
                natures       = new[] { Nature.Genetic }.ToSelectList();
                notations     = new[] { Notation.Nucleotides };
                remoteDbs     = EnumExtensions.ToArray <RemoteDb>().Where(rd => rd.GetNature() == Nature.Genetic);
                sequenceTypes = EnumExtensions.ToArray <SequenceType>().Where(st => st.GetNature() == Nature.Genetic);
                groups        = EnumExtensions.ToArray <Group>().Where(g => g.GetNature() == Nature.Genetic);
            }

            return(new Dictionary <string, object>
            {
                { "matters", matterRepository.GetMatterSelectList() },
                { "natures", natures },
                { "notations", notations.ToSelectListWithNature() },
                { "remoteDbs", remoteDbs.ToSelectListWithNature() },
                { "sequenceTypes", sequenceTypes.ToSelectListWithNature() },
                { "groups", groups.ToSelectListWithNature() },
                { "languages", EnumHelper.GetSelectList(typeof(Language)) },
                { "translators", EnumHelper.GetSelectList(typeof(Translator)) }
            });
        }
Пример #4
0
        /// <summary>
        /// Fills view data.
        /// </summary>
        /// <param name="minSelectedMatters">
        /// The minimum selected matters.
        /// </param>
        /// <param name="maxSelectedMatters">
        /// The maximum selected matters.
        /// </param>
        /// <param name="filter">
        /// The matters filter.
        /// </param>
        /// <param name="submitName">
        /// The submit button name.
        /// </param>
        /// <returns>
        /// The <see cref="Dictionary{String, Object}"/>.
        /// </returns>
        public Dictionary <string, object> FillViewData(int minSelectedMatters, int maxSelectedMatters, Func <Matter, bool> filter, string submitName)
        {
            Dictionary <string, object> data = GetMattersData(minSelectedMatters, maxSelectedMatters, filter);

            IEnumerable <SelectListItem> natures;
            IEnumerable <Notation>       notations;
            IEnumerable <SequenceType>   sequenceTypes;
            IEnumerable <Group>          groups;

            if (AccountHelper.IsAdmin())
            {
                natures       = EnumHelper.GetSelectList(typeof(Nature));
                notations     = EnumExtensions.ToArray <Notation>();
                sequenceTypes = EnumExtensions.ToArray <SequenceType>();
                groups        = EnumExtensions.ToArray <Group>();
            }
            else
            {
                natures       = new[] { Nature.Genetic }.ToSelectList();
                notations     = new[] { Notation.Nucleotides };
                sequenceTypes = EnumExtensions.ToArray <SequenceType>().Where(st => st.GetNature() == Nature.Genetic);
                groups        = EnumExtensions.ToArray <Group>().Where(g => g.GetNature() == Nature.Genetic);
            }

            data.Add("submitName", submitName);
            data.Add("natures", natures);
            data.Add("notations", notations.ToSelectListWithNature());
            data.Add("languages", EnumHelper.GetSelectList(typeof(Language)));
            data.Add("translators", EnumHelper.GetSelectList(typeof(Translator)));
            data.Add("pauseTreatments", EnumHelper.GetSelectList(typeof(PauseTreatment)));
            data.Add("sequenceTypes", sequenceTypes.ToSelectListWithNature(true));
            data.Add("groups", groups.ToSelectListWithNature(true));

            return(data);
        }
Пример #5
0
        private void TransformOrders()
        {
            // TODO: get rid of IndexOf here.
            int[] ordersIds = Orders.Select(o => Orders.IndexOf(o)).ToArray();
            TransformationsData = ordersIds.AsParallel().AsOrdered().Select(el => new OrderTransformationData
            {
                ResultTransformation = EnumExtensions.ToArray <OrderTransformation>().AsParallel().AsOrdered().Select(t => TransformOrder(t, el)).ToArray()
            }).ToArray();

            List <OrderTransformationData> resultData = ordersIds.AsParallel().AsOrdered().Select(el => new OrderTransformationData
            {
                ResultTransformation   = TransformationsData[el].ResultTransformation,
                UniqueFinalOrdersCount = CalculateUniqueOrdersCount(el)
            }).ToList();

            TransformationsData = resultData.ToArray();
        }
Пример #6
0
        private int CalculateUniqueOrdersCount(int id)
        {
            OrderTransformation[] transformationTypes = EnumExtensions.ToArray <OrderTransformation>();
            bool completed         = false;
            var  ordersForChecking = new List <int> {
                id
            };
            var checkedOrders = new List <int> {
                id
            };

            while (!completed)
            {
                var newOrders = new List <int>();
                foreach (int order in ordersForChecking)
                {
                    for (int i = 0; i < transformationTypes.Length; i++)
                    {
                        if (!checkedOrders.Contains(TransformationsData[order].ResultTransformation[i].OrderId))
                        {
                            checkedOrders.Add(TransformationsData[order].ResultTransformation[i].OrderId);
                            newOrders.Add(TransformationsData[order].ResultTransformation[i].OrderId);
                        }
                    }
                }
                if (newOrders.Count > 0)
                {
                    ordersForChecking = newOrders;
                }
                else
                {
                    completed = true;
                }
            }

            return(checkedOrders.Count);
        }
Пример #7
0
        public ActionResult Index(long[] matterIds, short characteristicLinkId, short[] characteristicLinkIds, Feature[] features)
        {
            return(CreateTask(() =>
            {
                matterIds = matterIds.OrderBy(m => m).ToArray();

                var matterNames = new string[matterIds.Length];
                var remoteIds = new string[matterIds.Length];
                var subsequencesCharacteristicsNames = new string[characteristicLinkIds.Length];
                var subsequencesCharacteristicsList = new SelectListItem[characteristicLinkIds.Length];
                var attributeValuesCache = new AttributeValueCacheManager();
                long[] sequenceIds;

                using (var db = new LibiadaWebEntities())
                {
                    DnaSequence[] parentSequences = db.DnaSequence.Include(s => s.Matter)
                                                    .Where(s => s.Notation == Notation.Nucleotides && matterIds.Contains(s.MatterId))
                                                    .OrderBy(s => s.MatterId)
                                                    .ToArray();

                    for (int n = 0; n < parentSequences.Length; n++)
                    {
                        matterNames[n] = parentSequences[n].Matter.Name;
                        remoteIds[n] = parentSequences[n].RemoteId;
                    }

                    var geneticSequenceRepository = new GeneticSequenceRepository(db);
                    sequenceIds = geneticSequenceRepository.GetNucleotideSequenceIds(matterIds);
                }

                var characteristicTypeLinkRepository = FullCharacteristicRepository.Instance;
                string sequenceCharacteristicName = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkId);

                for (int k = 0; k < characteristicLinkIds.Length; k++)
                {
                    subsequencesCharacteristicsNames[k] = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkIds[k]);
                    subsequencesCharacteristicsList[k] = new SelectListItem
                    {
                        Value = k.ToString(),
                        Text = subsequencesCharacteristicsNames[k],
                        Selected = false
                    };
                }

                double[] characteristics = SequencesCharacteristicsCalculator.Calculate(sequenceIds, characteristicLinkId);

                var sequencesData = new SequenceData[matterIds.Length];

                for (int i = 0; i < matterIds.Length; i++)
                {
                    // all subsequence calculations
                    SubsequenceData[] subsequencesData = CalculateSubsequencesCharacteristics(
                        characteristicLinkIds,
                        features,
                        sequenceIds[i]);

                    attributeValuesCache.FillAttributeValues(subsequencesData);

                    sequencesData[i] = new SequenceData(matterIds[i], matterNames[i], remoteIds[i], characteristics[i], subsequencesData);
                }

                // sorting organisms by their characteristic
                sequencesData = sequencesData.OrderBy(r => r.Characteristic).ToArray();
                List <AttributeValue> allAttributeValues = attributeValuesCache.AllAttributeValues;
                var result = new Dictionary <string, object>
                {
                    { "result", sequencesData },
                    { "subsequencesCharacteristicsNames", subsequencesCharacteristicsNames },
                    { "subsequencesCharacteristicsList", subsequencesCharacteristicsList },
                    { "sequenceCharacteristicName", sequenceCharacteristicName },
                    { "features", features.ToSelectList(features).ToDictionary(f => f.Value) },
                    { "attributes", EnumExtensions.ToArray <Attribute>().ToDictionary(a => (byte)a, a => a.GetDisplayValue()) },
                    { "attributeValues", allAttributeValues.Select(sa => new { attribute = sa.AttributeId, value = sa.Value }) }
                };

                return new Dictionary <string, string> {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }