Exemple #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"));
        }
Exemple #2
0
        public void TestIndexer()
        {
            DnaSequence dnaSequence = new DnaSequence("ACGT");

            Assert.AreEqual('C', (char)dnaSequence[1]);
            dnaSequence[2] = 'C';
        }
Exemple #3
0
 public void Setup()
 {
     dnaSequence1 = new DnaSequence(Mutante1);
     dnaSequence2 = new DnaSequence(Mutante2);
     dnaSequence3 = new DnaSequence(Mutante3);
     dnaSequence4 = new DnaSequence(Human1);
 }
Exemple #4
0
        public void TestElementAt()
        {
            DnaSequence dnaSequence = new DnaSequence("ACGT");
            DnaBase     dnaBase     = dnaSequence.ElementAt(1);

            Assert.AreEqual('C', (char)dnaBase);
        }
        public void TestEvolution()
        {
            DnaSequence dnaSequence     = new DnaSequence("AAA");
            DnaSequence evolvedSequence = DnaSequenceEvolver.evolver.Evolve(dnaSequence, 1);

            Assert.AreEqual(dnaSequence.Size(), evolvedSequence.Size());
        }
Exemple #6
0
        public void TestImplicitConvertionFromString()
        {
            string      dnaSequenceAsString = "AACCGGTGA";
            DnaSequence dnaSequence         = dnaSequenceAsString;

            Assert.AreEqual(dnaSequenceAsString, dnaSequence.PrintSequence());
        }
Exemple #7
0
        public void TestImplicitSequenceConvertion()
        {
            DnaSequence dnaSequence         = new DnaSequence("AACCGTCT");
            string      dnaSequenceAsString = dnaSequence;

            Assert.AreEqual("AACCGTCT", dnaSequenceAsString);
        }
Exemple #8
0
        public IEnumerable <ITestCaseData> GenerateFastaSequence_TestCases()
        {
            var singleLineNoTags = new DnaSequence(_normalizedNucleotides, AlphabetType.StrictDna, GeneticCode.Standard, new List <string> {
                _label
            });
            var multilineWithLabel = new DnaSequence(_normalizedNucleotides, AlphabetType.StrictDna, GeneticCode.Standard, new List <string> {
                _label
            });
            var multilineWithLabelAndTags = new DnaSequence(_normalizedNucleotides, AlphabetType.StrictDna, GeneticCode.Standard,
                                                            new List <string> {
                _label, "Hello world", "HODOR", "@MetadataFTW!", "Derp", "No"
            });

            yield return(new TestCaseData(_singleLineFasta, AlphabetType.StrictDna, singleLineNoTags).SetName("Single line FASTA sequence with label"));

            yield return(new TestCaseData(_multilineFastaWithLabel, AlphabetType.StrictDna, multilineWithLabel).SetName("Multiline FASTA with label"));

            yield return(new TestCaseData(_multilineFastaWithMetadataAndTrailingPipes, AlphabetType.StrictDna, multilineWithLabelAndTags)
                         .SetName("Multiline FASTA with label, tags, and empty trailing pipes"));

            yield return(new TestCaseData(_crossPlatformMultiLineN, AlphabetType.StrictDna, multilineWithLabelAndTags)
                         .SetName("Multiline FASTA with label, tags, and empty trailing pipes"));

            yield return(new TestCaseData(_crossPlatformMultiLineR, AlphabetType.StrictDna, multilineWithLabelAndTags)
                         .SetName("Multiline FASTA with label, tags, and empty trailing pipes"));
        }
        public ActionResult Index(long[] matterIds)
        {
            return(CreateTask(() =>
            {
                string[] matterNames;
                var results = new string[matterIds.Length];
                var statuses = new string[matterIds.Length];
                using (var db = new LibiadaWebEntities())
                {
                    matterNames = db.Matter
                                  .Where(m => matterIds.Contains(m.Id))
                                  .OrderBy(m => m.Id)
                                  .Select(m => m.Name)
                                  .ToArray();
                    var parentSequences = db.DnaSequence
                                          .Where(c => matterIds.Contains(c.MatterId))
                                          .OrderBy(c => c.MatterId)
                                          .ToArray();

                    for (int i = 0; i < parentSequences.Length; i++)
                    {
                        try
                        {
                            DnaSequence parentSequence = parentSequences[i];
                            using (var subsequenceImporter = new SubsequenceImporter(parentSequence))
                            {
                                subsequenceImporter.CreateSubsequences();
                            }

                            int featuresCount = db.Subsequence.Count(s => s.SequenceId == parentSequence.Id &&
                                                                     s.Feature != Feature.NonCodingSequence);
                            int nonCodingCount = db.Subsequence.Count(s => s.SequenceId == parentSequence.Id &&
                                                                      s.Feature == Feature.NonCodingSequence);

                            statuses[i] = "Success";
                            results[i] = $"Successfully imported {featuresCount} features and {nonCodingCount} non coding subsequences";
                        }
                        catch (Exception exception)
                        {
                            statuses[i] = "Error";
                            results[i] = exception.Message;
                            while (exception.InnerException != null)
                            {
                                results[i] += $" {exception.InnerException.Message}";

                                exception = exception.InnerException;
                            }
                        }
                    }
                }

                return new Dictionary <string, object>
                {
                    { "matterNames", matterNames },
                    { "results", results },
                    { "status", statuses }
                };
            }));
        }
Exemple #10
0
        public void TestDnaSequenceCreationFromInitializer()
        {
            DnaSequence dnaSequence = new DnaSequence()
            {
                "A", "C", "C", "T"
            };

            Assert.AreEqual("ACCT", dnaSequence.PrintSequence());
        }
 /// <summary>
 /// The to sequence.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <returns>
 /// The <see cref="CommonSequence"/>.
 /// </returns>
 private CommonSequence ToCommonSequence(DnaSequence source)
 {
     return(new CommonSequence
     {
         Id = source.Id,
         Notation = source.Notation,
         MatterId = source.MatterId
     });
 }
Exemple #12
0
        public void TestIteratingOverDnaSequence()
        {
            string      dnaSequenceAsString = "AGCTAAGG";
            int         iterator            = 0;
            DnaSequence dnaSequence         = new DnaSequence(dnaSequenceAsString);

            foreach (DnaBase dnaBase in dnaSequence)
            {
                Assert.AreEqual(dnaSequenceAsString.ElementAt(iterator), (char)dnaBase);
                iterator++;
            }
        }
        public IEnumerable <ITestCaseData> ComplementAndReverseComplement_TestCases()
        {
            var strictDnaComplement        = new DnaSequence(_strictDnaComplement, AlphabetType.StrictDna);
            var strictDnaReverseComplement = new DnaSequence(_strictDnaReverseComplement, AlphabetType.StrictDna);

            yield return(new TestCaseData(_strictDnaSequence, strictDnaComplement, strictDnaReverseComplement).SetName("DNA sequence complement and reverse complement"));

            var strictRna                  = new RnaSequence(_strictRna, AlphabetType.StrictRna);
            var strictRnaComplement        = new RnaSequence(_strictRnaComplement, AlphabetType.StrictRna);
            var strictRnaReverseComplement = new RnaSequence(_strictRnaReverseComplement, AlphabetType.StrictRna);

            yield return(new TestCaseData(strictRna, strictRnaComplement, strictRnaReverseComplement).SetName("RNA sequence complement and reverse complement"));
        }
        public IEnumerable <ITestCaseData> NucleotideCount_TestCases()
        {
            const string returnString = "{0} {1} in {2}";
            const string strictDna    = "ACCTTTGGGG";
            var          strictDnaSeq = new DnaSequence(strictDna, AlphabetType.StrictDna);

            yield return(new TestCaseData(strictDnaSeq, Nucleotide.Adenine).Returns(1).SetName(String.Format(returnString, 1, Nucleotide.Adenine, strictDna)));

            yield return(new TestCaseData(strictDnaSeq, Nucleotide.Cytosine).Returns(2).SetName(String.Format(returnString, 2, Nucleotide.Cytosine, strictDna)));

            yield return(new TestCaseData(strictDnaSeq, Nucleotide.Thymine).Returns(3).SetName(String.Format(returnString, 3, Nucleotide.Thymine, strictDna)));

            yield return(new TestCaseData(strictDnaSeq, Nucleotide.Guanine).Returns(4).SetName(String.Format(returnString, 4, Nucleotide.Guanine, strictDna)));

            var strictDnaSeqComplement = strictDnaSeq.Complement();

            yield return(new TestCaseData(strictDnaSeqComplement, Nucleotide.Thymine).Returns(1).SetName(String.Format(returnString, 1, Nucleotide.Thymine, strictDnaSeqComplement.Sequence)));

            yield return(new TestCaseData(strictDnaSeqComplement, Nucleotide.Guanine).Returns(2).SetName(String.Format(returnString, 2, Nucleotide.Guanine, strictDnaSeqComplement.Sequence)));

            yield return(new TestCaseData(strictDnaSeqComplement, Nucleotide.Adenine).Returns(3).SetName(String.Format(returnString, 3, Nucleotide.Adenine, strictDnaSeqComplement.Sequence)));

            yield return(new TestCaseData(strictDnaSeqComplement, Nucleotide.Cytosine).Returns(4).SetName(String.Format(returnString, 4, Nucleotide.Cytosine, strictDnaSeqComplement.Sequence)));

            const string ambiguousDna    = "GATCRYYWWWSSSSMMMMMKHBVDN";
            var          ambiguousDnaSeq = new DnaSequence(ambiguousDna, AlphabetType.AmbiguousDna);

            yield return(new TestCaseData(ambiguousDnaSeq, Nucleotide.NotAdenine).Returns(1).SetName(String.Format(returnString, 1, Nucleotide.NotAdenine, ambiguousDna)));

            yield return(new TestCaseData(ambiguousDnaSeq, Nucleotide.Purine).Returns(1).SetName(String.Format(returnString, 1, Nucleotide.Purine, ambiguousDna)));

            yield return(new TestCaseData(ambiguousDnaSeq, Nucleotide.Weak).Returns(3).SetName(String.Format(returnString, 3, Nucleotide.Weak, ambiguousDna)));

            yield return(new TestCaseData(ambiguousDnaSeq, Nucleotide.Strong).Returns(4).SetName(String.Format(returnString, 4, Nucleotide.Strong, ambiguousDna)));

            yield return(new TestCaseData(ambiguousDnaSeq, Nucleotide.Amino).Returns(5).SetName(String.Format(returnString, 5, Nucleotide.Amino, ambiguousDna)));

            yield return(new TestCaseData(ambiguousDnaSeq, Nucleotide.Keto).Returns(1).SetName(String.Format(returnString, 1, Nucleotide.Keto, ambiguousDna)));

            const string strictRna    = "ACCUUUGGGG";
            var          strictRnaSeq = new RnaSequence(strictRna, AlphabetType.StrictRna);

            yield return(new TestCaseData(strictRnaSeq, Nucleotide.Adenine).Returns(1).SetName(String.Format(returnString, 1, Nucleotide.Adenine, strictRna)));

            yield return(new TestCaseData(strictRnaSeq, Nucleotide.Cytosine).Returns(2).SetName(String.Format(returnString, 2, Nucleotide.Cytosine, strictRna)));

            yield return(new TestCaseData(strictRnaSeq, Nucleotide.Uracil).Returns(3).SetName(String.Format(returnString, 3, Nucleotide.Uracil, strictRna)));

            yield return(new TestCaseData(strictRnaSeq, Nucleotide.Guanine).Returns(4).SetName(String.Format(returnString, 4, Nucleotide.Guanine, strictRna)));
        }
        public IEnumerable <ITestCaseData> Tag_TestCases()
        {
            var tags = new HashSet <string> {
                "Foo", "Bar", "Baz"
            };
            var dna = new DnaSequence("ACTCTTCAGC", AlphabetType.StrictDna, GeneticCode.Standard, tags);

            yield return(new TestCaseData(dna, tags));

            var rna = new RnaSequence("AUCUAGCGCGUA", AlphabetType.StrictRna, GeneticCode.Standard, tags);

            yield return(new TestCaseData(rna, tags));

            var nullRna = new RnaSequence("AUCUAGCGCGUA", AlphabetType.StrictRna);

            yield return(new TestCaseData(nullRna, new List <string>()));
        }
        public IEnumerable <ITestCaseData> ComputeHammingDistance_TestCases()
        {
            var compDnaA = new DnaSequence(_strictDnaComplement, AlphabetType.StrictDna);

            yield return(new TestCaseData(_strictDnaSequence, _strictDnaSequence).Returns(0).SetName("Same DNA sequences return 0"));

            yield return(new TestCaseData(_strictDnaSequence, compDnaA).Returns(20).SetName("DNA sequences off by 20 characters return 20"));

            yield return(new TestCaseData(_strictDnaSequence, _strictDnaWithAmbiguousAlphabet).SetName("DNA sequences with different alphabets fails").Throws(typeof(ArgumentException)));

            var compRnaA = new RnaSequence(_strictRnaComplement, AlphabetType.StrictRna);

            yield return(new TestCaseData(_strictRnaSequence, _strictRnaSequence).Returns(0).SetName("Same RNA sequences return 0"));

            yield return(new TestCaseData(_strictRnaSequence, compRnaA).Returns(20).SetName("RNA sequences off by 20 characters return 20"));

            yield return(new TestCaseData(_strictRnaSequence, _strictRnaWithAmbiguousAlphabet).SetName("RNA sequences with different alphabets fails").Throws(typeof(ArgumentException)));

            yield return(new TestCaseData(_strictDnaSequence, _strictRnaSequence).SetName("Comparing an RNA sequence to a DNA sequence fails").Throws(typeof(ArgumentException)));
        }
Exemple #17
0
        public ActionResult Index(long matterId)
        {
            return(CreateTask(() =>
            {
                Dictionary <string, object> result;

                using (var db = new LibiadaWebEntities())
                {
                    DnaSequence parentSequence = db.DnaSequence.Single(d => d.MatterId == matterId);
                    using (var subsequenceImporter = new SubsequenceImporter(parentSequence))
                    {
                        subsequenceImporter.CreateSubsequences();
                    }

                    var features = EnumExtensions.ToArray <Feature>().ToDictionary(f => (byte)f, f => f.GetDisplayValue());
                    string matterName = db.Matter.Single(m => m.Id == matterId).Name;
                    SubsequenceData[] sequenceSubsequences = db.Subsequence
                                                             .Where(s => s.SequenceId == parentSequence.Id)
                                                             .Include(s => s.Position)
                                                             .ToArray()
                                                             .Select(s => new SubsequenceData(s))
                                                             .ToArray();

                    result = new Dictionary <string, object>
                    {
                        { "matterName", matterName },
                        { "genes", sequenceSubsequences },
                        { "features", features }
                    };
                }

                return new Dictionary <string, object>
                {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }
 /// <summary>
 /// The insert.
 /// </summary>
 /// <param name="sequence">
 /// The sequence.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 /// <param name="building">
 /// The building.
 /// </param>
 public void Insert(DnaSequence sequence, long[] alphabet, int[] building)
 {
     Create(ToCommonSequence(sequence), false, alphabet, building);
 }
Exemple #19
0
        public void TestSizeGetting()
        {
            DnaSequence dnaSequence = new DnaSequence("AAGC");

            Assert.AreEqual(4, dnaSequence.Size());
        }
Exemple #20
0
        public void TestSequencePrinting()
        {
            DnaSequence dnaSequence = new DnaSequence("AACCGTCT");

            Assert.AreEqual("AACCGTCT", dnaSequence.PrintSequence());
        }
        public ActionResult Index(long[] matterIds)
        {
            return(CreateTask(() =>
            {
                string[] matterNames;
                var importResults = new List <MatterImportResult>(matterIds.Length);

                using (var db = new LibiadaWebEntities())
                {
                    matterNames = Cache.GetInstance().Matters
                                  .Where(m => matterIds.Contains(m.Id))
                                  .OrderBy(m => m.Id)
                                  .Select(m => m.Name)
                                  .ToArray();
                    var parentSequences = db.DnaSequence
                                          .Where(c => matterIds.Contains(c.MatterId))
                                          .OrderBy(c => c.MatterId)
                                          .ToArray();

                    for (int i = 0; i < parentSequences.Length; i++)
                    {
                        var importResult = new MatterImportResult()
                        {
                            MatterName = matterNames[i]
                        };

                        try
                        {
                            DnaSequence parentSequence = parentSequences[i];
                            using (var subsequenceImporter = new SubsequenceImporter(parentSequence))
                            {
                                subsequenceImporter.CreateSubsequences();
                            }

                            int featuresCount = db.Subsequence.Count(s => s.SequenceId == parentSequence.Id &&
                                                                     s.Feature != Feature.NonCodingSequence);
                            int nonCodingCount = db.Subsequence.Count(s => s.SequenceId == parentSequence.Id &&
                                                                      s.Feature == Feature.NonCodingSequence);

                            importResult.Status = "Success";
                            importResult.Result = $"Successfully imported {featuresCount} features and {nonCodingCount} non coding subsequences";
                            importResults.Add(importResult);
                        }
                        catch (Exception exception)
                        {
                            importResult.Status = "Error";
                            importResult.Result = exception.Message;
                            while (exception.InnerException != null)
                            {
                                importResult.Result += $" {exception.InnerException.Message}";

                                exception = exception.InnerException;
                            }
                            importResults.Add(importResult);
                        }
                    }
                }

                var result = new Dictionary <string, object> {
                    { "result", importResults }
                };

                return new Dictionary <string, string> {
                    { "data", JsonConvert.SerializeObject(result) }
                };
            }));
        }
Exemple #22
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"));
        }
        public ActionResult Index(IEnumerable<long> matterIds, string transformType)
        {
            int notationId = transformType.Equals("toAmino") ? Aliases.Notation.AminoAcid : Aliases.Notation.Triplet;

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

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

                var result = new DnaSequence
                    {
                        MatterId = matterId,
                        NotationId = notationId
                    };

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

            return RedirectToAction("Index", "CommonSequences");
        }
Exemple #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SubsequenceImporter"/> class.
 /// </summary>
 /// <param name="sequence">
 /// Dna sequence for which subsequences will be imported.
 /// </param>
 public SubsequenceImporter(DnaSequence sequence) : this(NcbiHelper.GetFeatures(sequence.RemoteId), sequence.Id)
 {
 }
 /// <summary>
 /// The to sequence.
 /// </summary>
 /// <param name="source">
 /// The source.
 /// </param>
 /// <returns>
 /// The <see cref="CommonSequence"/>.
 /// </returns>
 private CommonSequence ToCommonSequence(DnaSequence source)
 {
     return new CommonSequence
     {
         Id = source.Id,
         NotationId = source.NotationId,
         MatterId = source.MatterId
     };
 }
        public void DnaSequenceConstructor_Tests(string nucleotides, AlphabetType alphabet)
        {
            var dna = new DnaSequence(nucleotides, alphabet);

            Assert.IsInstanceOf <DnaSequence>(dna);
        }
 /// <summary>
 /// The insert.
 /// </summary>
 /// <param name="sequence">
 /// The sequence.
 /// </param>
 /// <param name="alphabet">
 /// The alphabet.
 /// </param>
 /// <param name="building">
 /// The building.
 /// </param>
 public void Insert(DnaSequence sequence, long[] alphabet, int[] building)
 {
     Create(ToCommonSequence(sequence), false, alphabet, building);
 }