Example #1
0
        public ActionResult Index(long[] matterIds, short[] characteristicLinkIds, Feature[] features)
        {
            return(CreateTask(() =>
            {
                var sequencesData = new SequenceData[matterIds.Length];

                long[] parentSequenceIds;
                var matterNames = new string[matterIds.Length];
                var remoteIds = new string[matterIds.Length];
                var subsequencesCharacteristicsNames = new string[characteristicLinkIds.Length];
                var subsequencesCharacteristicsList = new SelectListItem[characteristicLinkIds.Length];

                using (var db = new LibiadaWebEntities())
                {
                    var parentSequences = db.DnaSequence.Include(s => s.Matter)
                                          .Where(s => s.Notation == Notation.Nucleotides && matterIds.Contains(s.MatterId))
                                          .Select(s => new { s.Id, MatterName = s.Matter.Name, s.RemoteId })
                                          .ToDictionary(s => s.Id);
                    parentSequenceIds = parentSequences.Keys.ToArray();

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

                FullCharacteristicRepository characteristicTypeLinkRepository = FullCharacteristicRepository.Instance;
                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
                    };
                }

                // TODO: Maybe AttributesValueCache should be created in the Subsequences calculator
                var attributeValuesCache = new AttributeValueCacheManager();

                for (int i = 0; i < parentSequenceIds.Length; i++)
                {
                    var subsequencesData = CalculateSubsequencesCharacteristics(characteristicLinkIds, features, parentSequenceIds[i]);

                    attributeValuesCache.FillAttributeValues(subsequencesData);

                    sequencesData[i] = new SequenceData(matterIds[i], matterNames[i], remoteIds[i], default, subsequencesData);
Example #2
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) }
                };
            }));
        }
Example #3
0
        public ActionResult Index(
            long[] matterIds,
            short characteristicLinkId,
            short subsequencesCharacteristicLinkId,
            Feature[] features,
            string maxPercentageDifference,
            string[] filters)
        {
            return(CreateTask(() =>
            {
                double percentageDifference = double.Parse(maxPercentageDifference, CultureInfo.InvariantCulture) / 100;

                var attributeValuesCache = new AttributeValueCacheManager();
                var characteristics = new SubsequenceData[matterIds.Length][];

                long[] parentSequenceIds;
                var matterNames = new string[matterIds.Length];

                int mattersCount = matterIds.Length;
                Dictionary <string, object> characteristicsTypesData;

                using (var db = new LibiadaWebEntities())
                {
                    // Sequences characteristic
                    var geneticSequenceRepository = new GeneticSequenceRepository(db);
                    long[] chains = geneticSequenceRepository.GetNucleotideSequenceIds(matterIds);

                    // Sequences characteristic
                    matterIds = OrderMatterIds(matterIds, characteristicLinkId, chains);

                    // Subsequences characteristics
                    var parentSequences = db.DnaSequence.Include(s => s.Matter)
                                          .Where(s => s.Notation == Notation.Nucleotides && matterIds.Contains(s.MatterId))
                                          .Select(s => new { s.Id, s.MatterId, MatterName = s.Matter.Name })
                                          .ToDictionary(s => s.Id);

                    parentSequenceIds = parentSequences
                                        .OrderBy(ps => Array.IndexOf(matterIds, ps.Value.MatterId))
                                        .Select(ps => ps.Key)
                                        .ToArray();

                    for (int n = 0; n < parentSequenceIds.Length; n++)
                    {
                        matterNames[n] = parentSequences[parentSequenceIds[n]].MatterName;
                    }

                    var viewDataHelper = new ViewDataHelper(db);
                    characteristicsTypesData = viewDataHelper.GetCharacteristicsData(CharacteristicCategory.Full);
                }

                FullCharacteristicRepository fullCharacteristicRepository = FullCharacteristicRepository.Instance;
                string sequenceCharacteristicName = fullCharacteristicRepository.GetCharacteristicName(characteristicLinkId);
                string characteristicName = fullCharacteristicRepository.GetCharacteristicName(subsequencesCharacteristicLinkId);

                var characteristicValueSubsequences = new Dictionary <double, List <(int matterIndex, int subsequenceIndex)> >();

                // cycle through matters
                for (int i = 0; i < mattersCount; i++)
                {
                    SubsequenceData[] subsequencesData = CalculateSubsequencesCharacteristics(
                        new[] { subsequencesCharacteristicLinkId },
                        features,
                        parentSequenceIds[i],
                        filters);

                    characteristics[i] = subsequencesData;
                    attributeValuesCache.FillAttributeValues(subsequencesData);

                    for (int j = 0; j < subsequencesData.Length; j++)
                    {
                        double value = subsequencesData[j].CharacteristicsValues[0];
                        if (characteristicValueSubsequences.TryGetValue(value, out List <(int matterIndex, int subsequenceIndex)> matterAndSubsequenceIdsList))
                        {
                            matterAndSubsequenceIdsList.Add((i, j));
                        }