示例#1
0
        public ActionResult Index(IEnumerable <long> matterIds, string transformType)
        {
            Notation notation = transformType.Equals("toAmino") ? Notation.AminoAcids : Notation.Triplets;

            foreach (var matterId in matterIds)
            {
                var   sequenceId  = db.CommonSequence.Single(c => c.MatterId == matterId && c.Notation == Notation.Nucleotides).Id;
                Chain sourceChain = commonSequenceRepository.GetLibiadaChain(sequenceId);

                BaseChain transformedChain = transformType.Equals("toAmino")
                                                 ? DnaTransformer.EncodeAmino(sourceChain)
                                                 : DnaTransformer.EncodeTriplets(sourceChain);

                var result = new DnaSequence
                {
                    MatterId = matterId,
                    Notation = notation
                };

                long[] alphabet = elementRepository.ToDbElements(transformedChain.Alphabet, notation, false);
                dnaSequenceRepository.Insert(result, alphabet, transformedChain.Building);
            }

            return(RedirectToAction("Index", "CommonSequences"));
        }
示例#2
0
        public ActionResult Index(long matterId,
                                  Notation notation,
                                  Language?language,
                                  Translator?translator,
                                  PauseTreatment?pauseTreatment,
                                  bool?sequentialTransfer,
                                  int scrambling)
        {
            Matter matter = Cache.GetInstance().Matters.Single(m => m.Id == matterId);
            long   sequenceId;

            switch (matter.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;
            }

            BaseChain chain = sequenceRepository.GetLibiadaBaseChain(sequenceId);

            for (int i = 0; i < scrambling; i++)
            {
                int firstIndex  = randomGenerator.Next(chain.Length);
                int secondIndex = randomGenerator.Next(chain.Length);

                IBaseObject firstElement  = chain[firstIndex];
                IBaseObject secondElement = chain[secondIndex];
                chain[firstIndex]  = secondElement;
                chain[secondIndex] = firstElement;
            }

            var resultMatter = new Matter
            {
                Nature = matter.Nature,
                Name   = $"{matter.Name} {scrambling} mixes"
            };
            MatterRepository matterRepository = new MatterRepository(db);

            matterRepository.SaveToDatabase(resultMatter);

            var result = new CommonSequence
            {
                Notation = notation,
                MatterId = resultMatter.Id
            };

            long[] alphabet = elementRepository.ToDbElements(chain.Alphabet, notation, false);

            switch (matter.Nature)
            {
            case Nature.Genetic:
                DnaSequence dnaSequence = db.DnaSequence.Single(c => c.Id == sequenceId);

                dnaSequenceRepository.Create(result, dnaSequence.Partial, alphabet, chain.Building);
                break;

            case Nature.Music:
                musicSequenceRepository.Create(result, alphabet, chain.Building);
                break;

            case Nature.Literature:
                LiteratureSequence sequence = db.LiteratureSequence.Single(c => c.Id == sequenceId);

                literatureSequenceRepository.Create(result, sequence.Original, sequence.Language, sequence.Translator, alphabet, chain.Building);
                break;

            case Nature.MeasurementData:
                dataSequenceRepository.Create(result, alphabet, chain.Building);
                break;

            default:
                throw new InvalidEnumArgumentException(nameof(matter.Nature), (int)matter.Nature, typeof(Nature));
            }

            return(RedirectToAction("Index", "Matters"));
        }
        /// <summary>
        /// The index.
        /// </summary>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        public ActionResult Index()
        {
            using (var db = new LibiadaWebEntities())
            {
                var           matterRepository         = new MatterRepository(db);
                var           dnaSequenceRepository    = new GeneticSequenceRepository(db);
                var           commonSequenceRepository = new CommonSequenceRepository(db);
                var           elementRepository        = new ElementRepository(db);
                var           matterIds = new long[] { 1332, 1333, 1339, 1330, 1337, 1342, 1331, 1338, 1340, 1943, 1945, 1334 };
                DnaSequence[] sequences = db.DnaSequence.Include(d => d.Matter).Where(d => matterIds.Contains(d.MatterId)).ToArray();

                for (int i = 0; i < sequences.Length; i++)
                {
                    var newMatter = new Matter
                    {
                        Name         = $"{sequences[i].Matter.Name} Cleaned of IS110",
                        Description  = sequences[i].Matter.Description,
                        Nature       = sequences[i].Matter.Nature,
                        Group        = sequences[i].Matter.Group,
                        SequenceType = sequences[i].Matter.SequenceType
                    };

                    var newSequence = new CommonSequence
                    {
                        Notation    = sequences[i].Notation,
                        Matter      = newMatter,
                        Description = sequences[i].Description,
                        RemoteDb    = sequences[i].RemoteDb,
                        RemoteId    = sequences[i].RemoteId
                    };
                    var chain = commonSequenceRepository.GetLibiadaChain(sequences[i].Id);

                    matterRepository.CreateOrExtractExistingMatterForSequence(newSequence);
                    dnaSequenceRepository.Create(newSequence, false, elementRepository.ToDbElements(chain.Alphabet, Notation.Nucleotides, false), chain.Building);
                    var sequenceId              = sequences[i].Id;
                    var subsequences            = db.Subsequence.Include(s => s.Position).Include(s => s.SequenceAttribute).Where(s => s.SequenceId == sequenceId).ToList();
                    var subsequenceIds          = subsequences.Select(s => s.Id);
                    var subsequencesIdsToRemove = db.SequenceAttribute
                                                  .Where(sa => subsequenceIds.Contains(sa.SequenceId) && sa.Value.Contains("IS110"))
                                                  .Select(sa => sa.SequenceId)
                                                  .Distinct()
                                                  .ToArray();

                    subsequences.RemoveAll(s => subsequencesIdsToRemove.Contains(s.Id));

                    var newSubsequences       = new Subsequence[subsequences.Count];
                    var newSequenceAttributes = new List <SequenceAttribute>();
                    var newPositions          = new List <Position>();
                    for (int j = 0; j < subsequences.Count; j++)
                    {
                        newSubsequences[j] = new Subsequence
                        {
                            Id         = db.GetNewElementId(),
                            Feature    = subsequences[j].Feature,
                            SequenceId = newSequence.Id,
                            Start      = subsequences[j].Start,
                            Length     = subsequences[j].Length,
                            RemoteId   = subsequences[j].RemoteId,
                            Partial    = subsequences[j].Partial
                        };

                        foreach (SequenceAttribute subsequenceAttribute in subsequences[j].SequenceAttribute.ToArray())
                        {
                            newSequenceAttributes.Add(new SequenceAttribute
                            {
                                SequenceId = newSubsequences[j].Id,
                                Attribute  = subsequenceAttribute.Attribute,
                                Value      = subsequenceAttribute.Value
                            });
                        }

                        foreach (Position position in subsequences[j].Position.ToArray())
                        {
                            newPositions.Add(new Position
                            {
                                SubsequenceId = newSubsequences[j].Id,
                                Length        = position.Length,
                                Start         = position.Start
                            });
                        }
                    }

                    db.Subsequence.AddRange(newSubsequences);
                    db.SequenceAttribute.AddRange(newSequenceAttributes);
                    db.Position.AddRange(newPositions);
                    db.SaveChanges();
                }
            }

            return(View());
        }