Beispiel #1
0
        public static string GetAlphabet(AlphabetType type)
        {
            switch (type)
            {
            case AlphabetType.EN:
                return(ALPHABET_EN);

            case AlphabetType.PL:
                return(ALPHABET_PL);

            case AlphabetType.EN_Digits:
                return(ALPHABET_EN + DIGITS);

            case AlphabetType.PL_Digits:
                return(ALPHABET_PL + DIGITS);

            case AlphabetType.EN_Digits_Extended:
                return(ALPHABET_EN + DIGITS + PUNCTUATION);

            case AlphabetType.PL_Digits_Extended:
                return(ALPHABET_PL + DIGITS + PUNCTUATION);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a course from json using a given AlphabetType.
        /// </summary>
        private static Course CreateCourse(AlphabetType alphabetType)
        {
            //determine resource id
            string resourceId = $"Alphabets.Resources.Database.{alphabetType}.Course.json";

            //get json string
            string json = FileHelper.TextResourceToString(resourceId);

            //deserialize json data
            CourseImport courseImport = JsonConvert.DeserializeObject <CourseImport>(json);

            //create lessons
            List <Lesson> lessons = new List <Lesson>();

            foreach (LessonImport lessonImport in courseImport.Lessons)
            {
                //create lesson parts
                List <LessonPart> lessonParts = new List <LessonPart>();
                foreach (LessonPartImport lessonPartImport in lessonImport.LessonParts)
                {
                    lessonParts.Add(new LessonPart(lessonPartType: lessonPartImport.LessonPartType, letter: lessonPartImport.Letter));
                }

                lessons.Add(new Lesson(cumulativeLetters: lessonImport.CumulativeLetters, lessonParts: lessonParts.ToArray()));
            }

            //create course
            return(new Course(alphabetType: AlphabetType.Georgian, lessons: lessons.ToArray()));
        }
Beispiel #3
0
 protected NucleotideSequence(string sequence, AlphabetType alphabet, GeneticCode geneticCode = GeneticCode.Standard, IEnumerable <string> tags = null)
     : this(sequence, alphabet, geneticCode)
 {
     if (tags != null)
     {
         _tags = new HashSet <string>(tags);
     }
 }
Beispiel #4
0
 internal override char[] ConvertPhonemes(char[] phones, AlphabetType alphabet)
 {
     if (alphabet == AlphabetType.Ipa)
     {
         return(phones);
     }
     return(_alphabetConverter.SapiToIpa(phones));
 }
 public void ProcessPhoneme(ref FragmentState fragmentState, AlphabetType alphabet, string ph, char[] phoneIds)
 {
     _writer.WriteStartElement("phoneme");
     if (alphabet != AlphabetType.Ipa)
     {
         _writer.WriteAttributeString("alphabet", (alphabet == AlphabetType.Sapi) ? "x-microsoft-sapi" : "x-microsoft-ups");
     }
     _writer.WriteAttributeString("ph", ph);
 }
Beispiel #6
0
 public void ProcessPhoneme(ref FragmentState fragmentState, AlphabetType alphabet, string ph, char[] phoneIds)
 {
     _writer.WriteStartElement("phoneme");
     if (alphabet != AlphabetType.Ipa)
     {
         _writer.WriteAttributeString("alphabet", alphabet == AlphabetType.Sapi ? "x-microsoft-sapi" : "x-microsoft-ups");
         System.Diagnostics.Debug.Assert(alphabet == AlphabetType.Ups || alphabet == AlphabetType.Sapi);
     }
     _writer.WriteAttributeString("ph", ph);
 }
Beispiel #7
0
        public void GenerateFastaSequenceTests(string rawSequence, AlphabetType sequenceAlphabet, ISequence expected)
        {
            var parser = new FastaParser(rawSequence, sequenceAlphabet);
            var actual = parser.Parse().First();

            Assert.AreEqual(expected.GetType(), actual.GetType());
            CollectionAssert.AreEquivalent(expected.Tags, actual.Tags);
            Assert.AreEqual(expected.Sequence, actual.Sequence);
            Assert.AreEqual(expected.ActiveAlphabet, actual.ActiveAlphabet);
        }
Beispiel #8
0
 protected NucleotideSequence(string sequence, AlphabetType alphabet, GeneticCode geneticCode, Dictionary <Nucleotide, long> symbolCounts, IEnumerable <string> tags)
 {
     NucleotideAlphabet = new NucleotideAlphabet(alphabet, geneticCode);
     ActiveAlphabet     = alphabet;
     GeneticCode        = geneticCode;
     Sequence           = sequence;
     SymbolCounts       = symbolCounts;
     if (tags != null)
     {
         _tags = new HashSet <string>(tags);
     }
 }
Beispiel #9
0
        protected NucleotideSequence(string sequence, AlphabetType alphabet, GeneticCode geneticCode)
        {
            NucleotideAlphabet = new NucleotideAlphabet(alphabet, geneticCode);
            ActiveAlphabet     = alphabet;
            GeneticCode        = geneticCode;
            var trimmedSequence = sequence.Trim();



            VerifyAndInitializeNucleotides(trimmedSequence);
            Sequence = trimmedSequence;
        }
        public NucleotideAlphabet(AlphabetType nucleotideAlphabet, GeneticCode geneticCode)
        {
            if (nucleotideAlphabet == AlphabetType.ExtendedProtein || nucleotideAlphabet == AlphabetType.StandardProtein)
            {
                throw new ArgumentException(String.Format(AlphabetDataProvider.InvalidNucleotideAlphabet, nucleotideAlphabet));
            }

            GeneticCode        = geneticCode;
            AllowedSymbols     = AlphabetDataProvider.GetAllowedNucleotideSymbols(nucleotideAlphabet);
            ComplementTable    = AlphabetDataProvider.GetComplementTable(nucleotideAlphabet);
            TranscriptionTable = AlphabetDataProvider.GetTranscriptionTable(nucleotideAlphabet);
            TranslationTable   = AlphabetDataProvider.GetTranslationTable(geneticCode, nucleotideAlphabet);
            GcContentSymbols   = AlphabetDataProvider.GcContentSymbols(nucleotideAlphabet);
        }
Beispiel #11
0
        public static ISet <AminoAcid> GetAllowedProteinSymbols(AlphabetType alphabet)
        {
            switch (alphabet)
            {
            case AlphabetType.ExtendedProtein:
                return(ExtendedProtein);

            case AlphabetType.StandardProtein:
                return(StandardProtein);

            default:
                throw new ArgumentException(String.Format(ProteinAlphabet.InvalidProteinAlphabet, alphabet));
            }
        }
Beispiel #12
0
        public RnaSequence(string rawBasePairs, AlphabetType alphabet, GeneticCode geneticCode = GeneticCode.Standard, IEnumerable <string> tags = null)
            : base(rawBasePairs, alphabet, geneticCode, tags)
        {
            switch (alphabet)
            {
            case AlphabetType.AmbiguousRna:
                break;

            case AlphabetType.StrictRna:
                break;

            default:
                throw new ArgumentException(String.Format(InvalidAlphabetForSequenceType, alphabet, GetType()));
            }
        }
Beispiel #13
0
        public ProteinAlphabet(AlphabetType proteinAlphabet, GeneticCode geneticCode = GeneticCode.Standard)
        {
            switch (proteinAlphabet)
            {
            case AlphabetType.ExtendedProtein:
                break;

            case AlphabetType.StandardProtein:
                break;

            default:
                throw new ArgumentException(String.Format(InvalidProteinAlphabet, proteinAlphabet));
            }
            _activeAlphabet = proteinAlphabet;
            _geneticCode    = geneticCode;
        }
        public static char[] Create(AlphabetType alphabetType)
        {
            switch (alphabetType)
            {
            case AlphabetType.None:
                throw new NotSupportedException();

            case AlphabetType.English:
                return("ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToArray());

            case AlphabetType.Russian:
                return("ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToArray());

            case AlphabetType.Count:
                throw new NotSupportedException();
            }

            throw new NotSupportedException();
        }
Beispiel #15
0
        /// <summary>
        /// Returns the proper complement table for the given nucleotide alphabet
        /// </summary>
        /// <param name="alphabet"></param>
        /// <returns></returns>
        public static IDictionary <Nucleotide, Nucleotide> GetComplementTable(AlphabetType alphabet)
        {
            switch (alphabet)
            {
            case AlphabetType.StrictDna:
                return(StrictDnaComplements);

            case AlphabetType.AmbiguousDna:
                return(AmbiguousDnaComplements);

            case AlphabetType.StrictRna:
                return(StrictRnaComplements);

            case AlphabetType.AmbiguousRna:
                return(AmbiguousRnaComplements);

            default:
                throw new ArgumentException(String.Format(InvalidNucleotideAlphabet, alphabet));
            }
        }
Beispiel #16
0
        /// <summary>
        /// Returns the transcription table for DNA to RNA conversions, or the back transcription table for RNA to DNA conversion. An RNA alphabet will return
        /// a DNA alphabet.
        /// </summary>
        /// <param name="nucleotideAlphabet"></param>
        /// <returns></returns>
        public static IDictionary <Nucleotide, Nucleotide> GetTranscriptionTable(AlphabetType nucleotideAlphabet)
        {
            switch (nucleotideAlphabet)
            {
            case AlphabetType.AmbiguousDna:
                return(AmbiguousDnaTranscriptionTable);

            case AlphabetType.StrictDna:
                return(UnambiguousDnaTranscriptionTable);

            case AlphabetType.AmbiguousRna:
                return(AmbiguousRnaTranscriptionTable);

            case AlphabetType.StrictRna:
                return(UnambiguousRnaTranslationTable);

            default:
                throw new ArgumentException(String.Format(InvalidNucleotideAlphabet, nucleotideAlphabet));
            }
        }
Beispiel #17
0
        /// <summary>
        /// Returns the set of symbols that are used to compute the GC content given an alphabet type
        /// </summary>
        /// <param name="alphabetType"></param>
        /// <returns></returns>
        public static ISet <Nucleotide> GcContentSymbols(AlphabetType alphabetType)
        {
            switch (alphabetType)
            {
            case AlphabetType.AmbiguousDna:
                return(AmbiguousAlphabetGcSymbols);

            case AlphabetType.AmbiguousRna:
                return(AmbiguousAlphabetGcSymbols);

            case AlphabetType.StrictDna:
                return(UnambiguousAlphabetGcSymbols);

            case AlphabetType.StrictRna:
                return(UnambiguousAlphabetGcSymbols);

            default:
                throw new ArgumentException(String.Format(InvalidNucleotideAlphabet, alphabetType));
            }
        }
Beispiel #18
0
        /// <summary>
        /// Returns the set of allowed symbols for a given nucleotide alphabet
        /// </summary>
        /// <param name="alphabet"></param>
        /// <returns></returns>
        public static ISet <Nucleotide> GetAllowedNucleotideSymbols(AlphabetType alphabet)
        {
            switch (alphabet)
            {
            case AlphabetType.StrictDna:
                return(StrictDna);

            case AlphabetType.AmbiguousDna:
                return(AmbiguousDna);

            case AlphabetType.StrictRna:
                return(StrictRna);

            case AlphabetType.AmbiguousRna:
                return(AmbiguousRna);

            default:
                throw new ArgumentException(String.Format(InvalidNucleotideAlphabet, alphabet));
            }
        }
Beispiel #19
0
        /// <summary>
        /// Creates an alphabet from json using a given AlphabetType.
        /// </summary>
        private static Alphabet CreateAlphabet(AlphabetType alphabetType)
        {
            //determine resource id
            string resourceId = $"Alphabets.Resources.Database.{alphabetType}.Alphabet.json";

            //get json string
            string json = FileHelper.TextResourceToString(resourceId);

            //deserialize json data
            AlphabetImport alphabetImport = JsonConvert.DeserializeObject <AlphabetImport>(json);

            //create letters
            List <Letter> letters = new List <Letter>();

            foreach (LetterImport letterImport in alphabetImport.Letters)
            {
                letters.Add(new Letter(cases: letterImport.Cases, transCases: letterImport.TransCases, pronounciationTips: letterImport.PronounciationTips, resourceId: letterImport.ResourceId));
            }

            //create alphabet
            return(new Alphabet(name: alphabetImport.Name, letters: letters.ToArray()));
        }
Beispiel #20
0
        public ProteinSequence(string rawSequence, AlphabetType desiredProteinAlphabet, GeneticCode geneticCode = GeneticCode.Standard)
        {
            switch (desiredProteinAlphabet)
            {
            case AlphabetType.ExtendedProtein:
                break;

            case AlphabetType.StandardProtein:
                break;

            default:
                throw new ArgumentException(String.Format(ProteinAlphabet.InvalidProteinAlphabet, desiredProteinAlphabet));
            }

            _proteinAlphabet = new ProteinAlphabet(desiredProteinAlphabet, geneticCode);
            ActiveAlphabet   = desiredProteinAlphabet;
            AllowedSymbols   = AlphabetDataProvider.GetAllowedProteinSymbols(ActiveAlphabet);

            _aminoCounts = new Dictionary <AminoAcid, long>(AllowedSymbols.Count);
            foreach (var symbol in AllowedSymbols)
            {
                _aminoCounts.Add(symbol, 0);
            }

            var trimmedRaw = rawSequence.Trim();

            foreach (var aminoCharacter in trimmedRaw)
            {
                var typedAmino = (AminoAcid)Char.ToUpperInvariant(aminoCharacter);
                if (!AllowedSymbols.Contains(typedAmino))
                {
                    throw new ArgumentException(String.Format(_invalidAminoAcidCharacter, aminoCharacter, _proteinAlphabet));
                }
                _aminoCounts[typedAmino]++;
            }
            Sequence = trimmedRaw;
        }
        public void RnaSequenceConstructor_TestCases(string nucleotides, AlphabetType alphabet)
        {
            var rna = new RnaSequence(nucleotides, alphabet);

            Assert.IsInstanceOf <RnaSequence>(rna);
        }
        public void DnaSequenceConstructor_Tests(string nucleotides, AlphabetType alphabet)
        {
            var dna = new DnaSequence(nucleotides, alphabet);

            Assert.IsInstanceOf <DnaSequence>(dna);
        }
 public void ProcessPhoneme(ref FragmentState fragmentState, AlphabetType alphabet, string ph, char[] phoneIds)
 {
     fragmentState.Action  = TtsEngineAction.Pronounce;
     fragmentState.Phoneme = _speakInfo.Voice.TtsEngine.ConvertPhonemes(phoneIds, alphabet);
 }
Beispiel #24
0
 internal RnaSequence(string safeSequence, AlphabetType alphabet, GeneticCode geneticCode, Dictionary <Nucleotide, long> symbolCounts, IEnumerable <string> tags = null)
     : base(safeSequence, alphabet, geneticCode, symbolCounts, tags)
 {
 }
Beispiel #25
0
 internal static RnaSequence FastRnaSequence(string safeSequence, AlphabetType alphabet, GeneticCode geneticCode, Dictionary <Nucleotide, long> symbolCounts, IEnumerable <string> tags = null)
 {
     return(new RnaSequence(safeSequence, alphabet, geneticCode, symbolCounts, tags));
 }
Beispiel #26
0
 public FastaParser(string fastaTextBlob, AlphabetType alphabet, GeneticCode geneticCode = GeneticCode.Standard) :
     this(alphabet, geneticCode)
 {
     _lines = Regex.Split(fastaTextBlob, Constants.CrossPlatformNewlines).ToList();
 }
Beispiel #27
0
 public FastaParser(IEnumerable <string> fastaText, AlphabetType alphabet, GeneticCode geneticCode = GeneticCode.Standard) :
     this(alphabet, geneticCode)
 {
     _lines.AddRange(fastaText);
 }
Beispiel #28
0
 public FastaParser(Uri pathToFasta, AlphabetType alphabet, GeneticCode geneticCode = GeneticCode.Standard) :
     this(alphabet, geneticCode)
 {
     _dataPath = pathToFasta;
 }
Beispiel #29
0
 private FastaParser(AlphabetType alphabet, GeneticCode geneticCode)
 {
     _geneticCode = geneticCode;
     _alphabet    = alphabet;
 }
Beispiel #30
0
        public int Constructor_Tests(string sequence, AlphabetType alphabet)
        {
            var protein = new ProteinSequence(sequence, alphabet, GeneticCode.Standard);

            return(protein.Sequence.Length);
        }