Beispiel #1
0
        public ActionResult Index(
            OrderTransformation[] transformationsSequence,
            int iterationsCount,
            string[] customSequences,
            bool localFile,
            HttpPostedFileBase[] file)
        {
            return(CreateTask(() =>
            {
                int sequencesCount = localFile ? Request.Files.Count : customSequences.Length;
                var sourceSequences = new string[sequencesCount];
                var sequences = new Chain[sequencesCount];
                var names = new string[sequencesCount];

                for (int i = 0; i < sequencesCount; i++)
                {
                    if (localFile)
                    {
                        var sequenceStream = FileHelper.GetFileStream(file[i]);
                        var fastaSequence = NcbiHelper.GetFastaSequence(sequenceStream);
                        sourceSequences[i] = fastaSequence.ConvertToString();
                        names[i] = fastaSequence.ID;
                    }
                    else
                    {
                        sourceSequences[i] = customSequences[i];
                        names[i] = $"Custom sequence {i + 1}. Length: {customSequences[i].Length}";
                    }
                }

                for (int k = 0; k < sequencesCount; k++)
                {
                    sequences[k] = new Chain(sourceSequences[k]);
                    for (int j = 0; j < iterationsCount; j++)
                    {
                        for (int i = 0; i < transformationsSequence.Length; i++)
                        {
                            sequences[k] = transformationsSequence[i] == OrderTransformation.Dissimilar
                                               ? DissimilarChainFactory.Create(sequences[k])
                                               : HighOrderFactory.Create(sequences[k], EnumExtensions.GetLink(transformationsSequence[i]));
                        }
                    }
                }

                var transformations = transformationsSequence.Select(ts => ts.GetDisplayValue());

                var result = new Dictionary <string, object>
                {
                    { "names", names },
                    { "sequences", sequences.Select((s, i) => new { name = names[i], value = s.ToString(" ") }).ToArray() },
                    { "transformationsList", transformations },
                    { "iterationsCount", iterationsCount }
                };

                return new Dictionary <string, string> {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }
Beispiel #2
0
        private OrderTransformationResult TransformOrder(OrderTransformation transformationType, int id)
        {
            var   transformationResult = new OrderTransformationResult();
            Chain chain = transformationType == OrderTransformation.Dissimilar
                              ? DissimilarChainFactory.Create(new BaseChain(Orders[id]))
                              : HighOrderFactory.Create(new Chain(Orders[id]), transformationType.GetLink());

            for (int i = 0; i < Orders.Count; i++)
            {
                if (Orders[i].SequenceEqual(chain.Building))
                {
                    transformationResult.OrderId        = i;
                    transformationResult.Transformation = transformationType.GetDisplayValue();
                    break;
                }
            }
            return(transformationResult);
        }
        public ActionResult Index(long matterId, OrderTransformation[] transformationsSequence, int iterationsCount)
        {
            return(CreateTask(() =>
            {
                var sequenceId = db.CommonSequence.Single(c => c.MatterId == matterId).Id;
                var sequence = commonSequenceRepository.GetLibiadaChain(sequenceId);
                for (int j = 0; j < iterationsCount; j++)
                {
                    for (int i = 0; i < transformationsSequence.Length; i++)
                    {
                        sequence = transformationsSequence[i] == OrderTransformation.Dissimilar ? DissimilarChainFactory.Create(sequence)
                                                             : HighOrderFactory.Create(sequence, EnumExtensions.GetLink(transformationsSequence[i]));
                    }
                }

                var transformations = new Dictionary <int, string>();
                for (int i = 0; i < transformationsSequence.Length; i++)
                {
                    transformations.Add(i, transformationsSequence[i].GetDisplayValue());
                }

                var result = new Dictionary <string, object>
                {
                    { "chain", sequence.ToString(" ") },
                    { "transformationsList", transformations },
                    { "iterationsCount", iterationsCount }
                };
                return new Dictionary <string, object>
                {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }
        public ActionResult Index(long matterId, OrderTransformation[] transformationsSequence, int iterationsCount)
        {
            return(CreateTask(() =>
            {
                var sequenceId = db.CommonSequence.Single(c => c.MatterId == matterId).Id;
                var sequence = commonSequenceRepository.GetLibiadaChain(sequenceId);
                int loopIteration = -1;
                int lastIteration = -1;
                var transformationsResult = new List <int[]>();
                transformationsResult.Add(sequence.Building);

                for (int j = 0; j < iterationsCount; j++)
                {
                    for (int i = 0; i < transformationsSequence.Length; i++)
                    {
                        sequence = transformationsSequence[i] == OrderTransformation.Dissimilar ? DissimilarChainFactory.Create(sequence)
                                                             : HighOrderFactory.Create(sequence, EnumExtensions.GetLink(transformationsSequence[i]));

                        if (transformationsResult.Any(tr => tr.SequenceEqual(sequence.Building)))
                        {
                            loopIteration = transformationsResult.FindIndex(tr => tr.SequenceEqual(sequence.Building)) + 1;
                            lastIteration = j + 1;
                            goto exitLoops;
                        }
                        transformationsResult.Add(sequence.Building);
                    }
                }

                exitLoops:

                var transformations = new Dictionary <int, string>();
                for (int i = 0; i < transformationsSequence.Length; i++)
                {
                    transformations.Add(i, transformationsSequence[i].GetDisplayValue());
                }

                var result = new Dictionary <string, object>
                {
                    { "chain", sequence },
                    { "transformationsList", transformations },
                    { "iterationsCount", iterationsCount },
                    { "transformationsResult", transformationsResult },
                    { "loopIteration", loopIteration },
                    { "lastIteration", lastIteration }
                };
                return new Dictionary <string, object>
                {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }
Beispiel #5
0
        public ActionResult Index(
            OrderTransformation[] transformationsSequence,
            int iterationsCount,
            short[] characteristicLinkIds,
            string[] customSequences,
            bool localFile,
            HttpPostedFileBase[] file)
        {
            return(CreateTask(() =>
            {
                var characteristicTypeLinkRepository = FullCharacteristicRepository.Instance;
                int sequencesCount = localFile ? Request.Files.Count : customSequences.Length;
                var sequences = new string[sequencesCount];
                var sequencesNames = new string[sequencesCount];

                for (int i = 0; i < sequencesCount; i++)
                {
                    if (localFile)
                    {
                        Stream sequenceStream = FileHelper.GetFileStream(file[i]);
                        ISequence fastaSequence = NcbiHelper.GetFastaSequence(sequenceStream);
                        sequences[i] = fastaSequence.ConvertToString();
                        sequencesNames[i] = fastaSequence.ID;
                    }
                    else
                    {
                        sequences[i] = customSequences[i];
                        sequencesNames[i] = $"Custom sequence {i + 1}. Length: {customSequences[i].Length}";
                    }
                }

                var sequencesCharacteristics = new SequenceCharacteristics[sequences.Length];
                for (int j = 0; j < sequences.Length; j++)
                {
                    var characteristics = new double[characteristicLinkIds.Length];
                    for (int k = 0; k < characteristicLinkIds.Length; k++)
                    {
                        var sequence = new Chain(sequences[j]);
                        for (int l = 0; l < iterationsCount; l++)
                        {
                            for (int w = 0; w < transformationsSequence.Length; w++)
                            {
                                sequence = transformationsSequence[w] == OrderTransformation.Dissimilar ? DissimilarChainFactory.Create(sequence)
                                                                     : HighOrderFactory.Create(sequence, EnumExtensions.GetLink(transformationsSequence[w]));
                            }
                        }

                        Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkIds[k]);
                        FullCharacteristic characteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkIds[k]);
                        IFullCalculator calculator = FullCalculatorsFactory.CreateCalculator(characteristic);

                        characteristics[k] = calculator.Calculate(sequence, link);
                    }

                    sequencesCharacteristics[j] = new SequenceCharacteristics
                    {
                        MatterName = sequencesNames[j],
                        Characteristics = characteristics
                    };
                }

                string[] characteristicNames = characteristicLinkIds.Select(c => characteristicTypeLinkRepository.GetCharacteristicName(c)).ToArray();

                var characteristicsList = new SelectListItem[characteristicLinkIds.Length];
                for (int i = 0; i < characteristicNames.Length; i++)
                {
                    characteristicsList[i] = new SelectListItem
                    {
                        Value = i.ToString(),
                        Text = characteristicNames[i],
                        Selected = false
                    };
                }

                var transformations = new Dictionary <int, string>();
                for (int i = 0; i < transformationsSequence.Length; i++)
                {
                    transformations.Add(i, transformationsSequence[i].GetDisplayValue());
                }

                var result = new Dictionary <string, object>
                {
                    { "characteristics", sequencesCharacteristics },
                    { "characteristicNames", characteristicNames },
                    { "characteristicsList", characteristicsList },
                    { "transformationsList", transformations },
                    { "iterationsCount", iterationsCount }
                };

                return new Dictionary <string, object>
                {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }
Beispiel #6
0
        public ActionResult Index(
            long[] matterIds,
            OrderTransformation[] transformationsSequence,
            int iterationsCount,
            short[] characteristicLinkIds,
            Notation[] notations,
            Language[] languages,
            Translator?[] translators,
            PauseTreatment[] pauseTreatments,
            bool[] sequentialTransfers)
        {
            return(CreateTask(() =>
            {
                var db = new LibiadaWebEntities();
                var characteristicTypeLinkRepository = FullCharacteristicRepository.Instance;
                var commonSequenceRepository = new CommonSequenceRepository(db);
                var mattersCharacteristics = new object[matterIds.Length];
                matterIds = matterIds.OrderBy(m => m).ToArray();
                Dictionary <long, Matter> matters = db.Matter.Where(m => matterIds.Contains(m.Id)).ToDictionary(m => m.Id);

                for (int i = 0; i < matterIds.Length; i++)
                {
                    long matterId = matterIds[i];
                    var characteristics = new double[characteristicLinkIds.Length];
                    for (int k = 0; k < characteristicLinkIds.Length; k++)
                    {
                        Notation notation = notations[k];
                        long sequenceId;
                        switch (matters[matterId].Nature)
                        {
                        case Nature.Literature:
                            Language language = languages[k];
                            Translator translator = translators[k] ?? Translator.NoneOrManual;
                            sequenceId = db.LiteratureSequence.Single(l => l.MatterId == matterId &&
                                                                      l.Notation == notation &&
                                                                      l.Language == language &&
                                                                      l.Translator == translator).Id;
                            break;

                        case Nature.Music:
                            PauseTreatment pauseTreatment = pauseTreatments[k];
                            bool sequentialTransfer = sequentialTransfers[k];
                            sequenceId = db.MusicSequence.Single(m => m.MatterId == matterId &&
                                                                 m.Notation == notation &&
                                                                 m.PauseTreatment == pauseTreatment &&
                                                                 m.SequentialTransfer == sequentialTransfer).Id;
                            break;

                        default:
                            sequenceId = db.CommonSequence.Single(c => c.MatterId == matterId && c.Notation == notation).Id;
                            break;
                        }

                        Chain sequence = commonSequenceRepository.GetLibiadaChain(sequenceId);
                        for (int l = 0; l < iterationsCount; l++)
                        {
                            for (int j = 0; j < transformationsSequence.Length; j++)
                            {
                                sequence = transformationsSequence[j] == OrderTransformation.Dissimilar ? DissimilarChainFactory.Create(sequence)
                                                                     : HighOrderFactory.Create(sequence, EnumExtensions.GetLink(transformationsSequence[j]));
                            }
                        }

                        int characteristicLinkId = characteristicLinkIds[k];
                        Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId);
                        FullCharacteristic characteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId);

                        IFullCalculator calculator = FullCalculatorsFactory.CreateCalculator(characteristic);
                        characteristics[k] = calculator.Calculate(sequence, link);
                    }

                    mattersCharacteristics[i] = new { matterName = matters[matterId].Name, characteristics };
                }

                var characteristicNames = new string[characteristicLinkIds.Length];
                for (int k = 0; k < characteristicLinkIds.Length; k++)
                {
                    characteristicNames[k] = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkIds[k], notations[k]);
                }

                var characteristicsList = new SelectListItem[characteristicLinkIds.Length];
                for (int i = 0; i < characteristicNames.Length; i++)
                {
                    characteristicsList[i] = new SelectListItem
                    {
                        Value = i.ToString(),
                        Text = characteristicNames[i],
                        Selected = false
                    };
                }

                var transformations = new Dictionary <int, string>();
                for (int i = 0; i < transformationsSequence.Length; i++)
                {
                    transformations.Add(i, transformationsSequence[i].GetDisplayValue());
                }

                var result = new Dictionary <string, object>
                {
                    { "characteristics", mattersCharacteristics },
                    { "characteristicNames", characteristicNames },
                    { "characteristicsList", characteristicsList },
                    { "transformationsList", transformations },
                    { "iterationsCount", iterationsCount }
                };

                return new Dictionary <string, object>
                {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }
Beispiel #7
0
        public ActionResult Index(
            long[] matterIds,
            OrderTransformation[] transformationsSequence,
            int iterationsCount,
            short characteristicLinkId,
            Notation notation,
            Language?language,
            Translator?translator,
            PauseTreatment?pauseTreatment,
            bool?sequentialTransfer)
        {
            return(CreateTask(() =>
            {
                var db = new LibiadaWebEntities();
                var characteristicTypeLinkRepository = FullCharacteristicRepository.Instance;
                var commonSequenceRepository = new CommonSequenceRepository(db);
                var mattersCharacteristics = new object[matterIds.Length];
                matterIds = matterIds.OrderBy(m => m).ToArray();
                Dictionary <long, Matter> matters = db.Matter.Where(m => matterIds.Contains(m.Id)).ToDictionary(m => m.Id);

                for (int i = 0; i < matterIds.Length; i++)
                {
                    long matterId = matterIds[i];
                    long sequenceId;
                    switch (matters[matterId].Nature)
                    {
                    case Nature.Literature:
                        sequenceId = db.LiteratureSequence.Single(l => l.MatterId == matterId &&
                                                                  l.Notation == notation &&
                                                                  l.Language == language &&
                                                                  l.Translator == translator).Id;
                        break;

                    case Nature.Music:
                        sequenceId = db.MusicSequence.Single(m => m.MatterId == matterId &&
                                                             m.Notation == notation &&
                                                             m.PauseTreatment == pauseTreatment &&
                                                             m.SequentialTransfer == sequentialTransfer).Id;
                        break;

                    default:
                        sequenceId = db.CommonSequence.Single(c => c.MatterId == matterId && c.Notation == notation).Id;
                        break;
                    }

                    Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId);
                    FullCharacteristic characteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId);
                    IFullCalculator calculator = FullCalculatorsFactory.CreateCalculator(characteristic);

                    Chain sequence = commonSequenceRepository.GetLibiadaChain(sequenceId);

                    var characteristics = new double[transformationsSequence.Length * iterationsCount];
                    for (int j = 0; j < iterationsCount; j++)
                    {
                        for (int k = 0; k < transformationsSequence.Length; k++)
                        {
                            sequence = transformationsSequence[k] == OrderTransformation.Dissimilar ? DissimilarChainFactory.Create(sequence)
                                                                 : HighOrderFactory.Create(sequence, transformationsSequence[k].GetLink());
                            characteristics[transformationsSequence.Length * j + k] = calculator.Calculate(sequence, link);
                        }
                    }

                    mattersCharacteristics[i] = new { matterName = matters[matterId].Name, characteristics };
                }

                string characteristicName = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkId, notation);


                var result = new Dictionary <string, object>
                {
                    { "characteristics", mattersCharacteristics },
                    { "characteristicName", characteristicName },
                    { "transformationsList", transformationsSequence.Select(ts => ts.GetDisplayValue()) },
                    { "iterationsCount", iterationsCount }
                };

                return new Dictionary <string, object>
                {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }
        public ActionResult Index(
            long[] matterIds,
            OrderTransformation[] transformationsSequence,
            int iterationsCount,
            short[] characteristicLinkIds,
            Notation[] notations,
            Language?[] languages,
            Translator?[] translators,
            PauseTreatment?[] pauseTreatments,
            bool?[] sequentialTransfers,
            ImageOrderExtractor?[] trajectories)
        {
            return(CreateTask(() =>
            {
                Dictionary <long, string> mattersNames = Cache.GetInstance().Matters.Where(m => matterIds.Contains(m.Id)).ToDictionary(m => m.Id, m => m.Name);
                Chain[][] sequences = new Chain[matterIds.Length][];

                using (var db = new LibiadaWebEntities())
                {
                    var commonSequenceRepository = new CommonSequenceRepository(db);
                    long[][] sequenceIds = commonSequenceRepository.GetSequenceIds(matterIds,
                                                                                   notations,
                                                                                   languages,
                                                                                   translators,
                                                                                   pauseTreatments,
                                                                                   sequentialTransfers,
                                                                                   trajectories);
                    for (int i = 0; i < matterIds.Length; i++)
                    {
                        sequences[i] = new Chain[characteristicLinkIds.Length];
                        for (int j = 0; j < characteristicLinkIds.Length; j++)
                        {
                            sequences[i][j] = commonSequenceRepository.GetLibiadaChain(sequenceIds[i][j]);
                        }
                    }
                }

                var characteristicTypeLinkRepository = FullCharacteristicRepository.Instance;
                var sequencesCharacteristics = new SequenceCharacteristics[matterIds.Length];
                matterIds = matterIds.OrderBy(m => m).ToArray();

                for (int i = 0; i < matterIds.Length; i++)
                {
                    long matterId = matterIds[i];
                    var characteristics = new double[characteristicLinkIds.Length];
                    for (int j = 0; j < characteristicLinkIds.Length; j++)
                    {
                        Notation notation = notations[j];


                        Chain sequence = sequences[i][j];
                        for (int l = 0; l < iterationsCount; l++)
                        {
                            for (int k = 0; k < transformationsSequence.Length; k++)
                            {
                                sequence = transformationsSequence[k] == OrderTransformation.Dissimilar ? DissimilarChainFactory.Create(sequence)
                                                                     : HighOrderFactory.Create(sequence, EnumExtensions.GetLink(transformationsSequence[k]));
                            }
                        }

                        int characteristicLinkId = characteristicLinkIds[j];
                        Link link = characteristicTypeLinkRepository.GetLinkForCharacteristic(characteristicLinkId);
                        FullCharacteristic characteristic = characteristicTypeLinkRepository.GetCharacteristic(characteristicLinkId);

                        IFullCalculator calculator = FullCalculatorsFactory.CreateCalculator(characteristic);
                        characteristics[j] = calculator.Calculate(sequence, link);
                    }

                    sequencesCharacteristics[i] = new SequenceCharacteristics
                    {
                        MatterName = mattersNames[matterId],
                        Characteristics = characteristics
                    };
                }

                var characteristicNames = new string[characteristicLinkIds.Length];
                var characteristicsList = new SelectListItem[characteristicLinkIds.Length];
                for (int k = 0; k < characteristicLinkIds.Length; k++)
                {
                    characteristicNames[k] = characteristicTypeLinkRepository.GetCharacteristicName(characteristicLinkIds[k], notations[k]);
                    characteristicsList[k] = new SelectListItem
                    {
                        Value = k.ToString(),
                        Text = characteristicNames[k],
                        Selected = false
                    };
                }

                var transformations = transformationsSequence.Select(ts => ts.GetDisplayValue());

                var result = new Dictionary <string, object>
                {
                    { "characteristics", sequencesCharacteristics },
                    { "characteristicNames", characteristicNames },
                    { "characteristicsList", characteristicsList },
                    { "transformationsList", transformations },
                    { "iterationsCount", iterationsCount }
                };

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