ToDbElements() 공개 메소드

The to db elements.
/// Thrown if alphabet element is not found in db. ///
public ToDbElements ( Alphabet alphabet, int notationId, bool createElements ) : long[]
alphabet Alphabet /// The alphabet. ///
notationId int /// The notation id. ///
createElements bool /// The create elements. ///
리턴 long[]
        /// <summary>
        /// Creates literature sequence in database.
        /// </summary>
        /// <param name="commonSequence">
        /// The common sequence.
        /// </param>
        /// <param name="sequenceStream">
        /// The sequence stream.
        /// </param>
        /// <param name="language">
        /// The language id.
        /// </param>
        /// <param name="original">
        /// The original.
        /// </param>
        /// <param name="translator">
        /// The translator id.
        /// </param>
        /// <param name="dropPunctuation">
        /// Flag indicating if punctuation should be removed from text.
        /// </param>
        public void Create(CommonSequence commonSequence, Stream sequenceStream, Language language, bool original, Translator translator, bool dropPunctuation = false)
        {
            string    stringSequence = FileHelper.ReadSequenceFromStream(sequenceStream);
            BaseChain chain;

            if (commonSequence.Notation == Notation.Letters)
            {
                stringSequence = stringSequence.ToUpper();
                if (dropPunctuation)
                {
                    stringSequence = new string(stringSequence.Where(c => !char.IsPunctuation(c)).ToArray());
                }
                chain = new BaseChain(stringSequence);
            }
            else
            {
                // file always contains empty string at the end
                // TODO: rewrite this, add empty string check at the end or write a normal trim
                string[] text = stringSequence.Split(new[] { '\n', '\r', ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                chain = new BaseChain(text.Select(e => (ValueString)e).Cast <IBaseObject>().ToList());
            }

            MatterRepository.CreateOrExtractExistingMatterForSequence(commonSequence);

            long[] alphabet = ElementRepository.ToDbElements(chain.Alphabet, commonSequence.Notation, true);
            Create(commonSequence, original, language, translator, alphabet, chain.Building);
        }
예제 #2
0
        /// <summary>
        /// Create data sequence and matter.
        /// </summary>
        /// <param name="sequence">
        /// The common sequence.
        /// </param>
        /// <param name="sequenceStream">
        /// The sequence stream.
        /// </param>
        /// <param name="precision">
        /// Precision of data sequence.
        /// </param>
        public void Create(CommonSequence sequence, Stream sequenceStream, int precision)
        {
            string stringSequence = FileHelper.ReadSequenceFromStream(sequenceStream);

            string[] text = stringSequence.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

            string[] cleanedSequence = text.Where(t => !t.Equals("\"volume\"") && !string.IsNullOrEmpty(t) && !string.IsNullOrWhiteSpace(t)).ToArray();

            var elements = new List <IBaseObject>(cleanedSequence.Length);

            for (int i = 0; i < cleanedSequence.Length; i++)
            {
                string element = cleanedSequence[i];
                if (element.Substring(element.Length - 2, 2).Equals(".0"))
                {
                    cleanedSequence[i] = cleanedSequence[i].Substring(0, cleanedSequence[i].Length - 2);
                }

                int intElement = int.Parse(cleanedSequence[i]);
                int multiplier = (int)Math.Pow(10, precision);
                intElement /= multiplier;
                intElement *= multiplier;

                elements.Add(new ValueInt(intElement));
            }

            var chain = new BaseChain(elements);

            MatterRepository.CreateOrExtractExistingMatterForSequence(sequence);

            long[] alphabet = ElementRepository.ToDbElements(chain.Alphabet, sequence.Notation, true);
            Create(sequence, alphabet, chain.Building);
        }
        /// <summary>
        /// The create DNA sequence.
        /// </summary>
        /// <param name="sequence">
        /// The common sequence.
        /// </param>
        /// <param name="fastaSequence">
        /// Sequence as <see cref="ISequence"/>>.
        /// </param>
        /// <param name="partial">
        /// The partial.
        /// </param>
        /// <exception cref="Exception">
        /// Thrown if at least one element of new sequence is missing in db
        /// or if sequence is empty or invalid.
        /// </exception>
        public void Create(CommonSequence sequence, ISequence fastaSequence, bool partial)
        {
            if (fastaSequence.ID.Contains("Resource temporarily unavailable"))
            {
                throw new Exception("Sequence is empty or invalid (probably ncbi is not responding).");
            }

            string stringSequence = fastaSequence.ConvertToString().ToUpper();

            var chain = new BaseChain(stringSequence);

            if (!ElementRepository.ElementsInDb(chain.Alphabet, sequence.Notation))
            {
                throw new Exception("At least one element of new sequence is invalid (not A, C, T, G or U).");
            }

            MatterRepository.CreateOrExtractExistingMatterForSequence(sequence);

            long[] alphabet = ElementRepository.ToDbElements(chain.Alphabet, sequence.Notation, false);
            Create(sequence, partial, alphabet, chain.Building);
        }