The matter repository.
Inheritance: IMatterRepository
        /// <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);
        }
Exemple #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>
 /// Initializes a new instance of the <see cref="ViewDataHelper"/> class.
 /// </summary>
 /// <param name="db">
 /// The db.
 /// </param>
 public ViewDataHelper(LibiadaWebEntities db)
 {
     this.db = db;
     matterRepository = new MatterRepository(db);
     notationRepository = new NotationRepository(db);
     featureRepository = new FeatureRepository(db);
     characteristicTypeLinkRepository = new CharacteristicTypeLinkRepository(db);
     remoteDbRepository = new RemoteDbRepository(db);
 }
        /// <summary>
        /// The create.
        /// </summary>
        /// <param name="sequence">
        /// The sequence.
        /// </param>
        /// <param name="sequenceStream">
        /// The sequence stream.
        /// </param>
        /// <exception cref="Exception">
        /// Thrown if congeneric tracks count not equals 1 (track is not monophonic).
        /// </exception>
        public void Create(CommonSequence sequence, Stream sequenceStream)
        {
            string stringSequence = FileHelper.ReadSequenceFromStream(sequenceStream);
            var    doc            = new XmlDocument();

            doc.LoadXml(stringSequence);

            var parser = new MusicXmlParser();

            parser.Execute(doc);
            ScoreTrack tempTrack = parser.ScoreModel;

            if (tempTrack.CongenericScoreTracks.Count != 1)
            {
                throw new Exception("Track contains more then one or zero congeneric score tracks (parts).");
            }

            MatterRepository.CreateOrExtractExistingMatterForSequence(sequence);

            BaseChain notesSequence = ConvertCongenericScoreTrackToNotesBaseChain(tempTrack.CongenericScoreTracks[0]);

            long[] notesAlphabet = ElementRepository.GetOrCreateNotesInDb(notesSequence.Alphabet);
            sequence.Notation = Notation.Notes;
            Create(sequence, notesAlphabet, notesSequence.Building);

            BaseChain measuresSequence = ConvertCongenericScoreTrackToMeasuresBaseChain(tempTrack.CongenericScoreTracks[0]);

            long[] measuresAlphabet = MeasureRepository.GetOrCreateMeasuresInDb(measuresSequence.Alphabet);
            sequence.Notation = Notation.Measures;
            sequence.Id       = default;
            Create(sequence, measuresAlphabet, measuresSequence.Building);

            sequence.Notation = Notation.FormalMotifs;
            var pauseTreatments = EnumExtensions.ToArray <PauseTreatment>().Where(pt => pt != PauseTreatment.NotApplicable);

            foreach (PauseTreatment pauseTreatment in pauseTreatments)
            {
                BaseChain fmotifsSequence = ConvertCongenericScoreTrackToFormalMotifsBaseChain(tempTrack.CongenericScoreTracks[0], pauseTreatment, false);
                long[]    fmotifsAlphabet = FmotifRepository.GetOrCreateFmotifsInDb(fmotifsSequence.Alphabet);
                sequence.Id = default;
                Create(sequence, fmotifsAlphabet, fmotifsSequence.Building, pauseTreatment, false);

                fmotifsSequence = ConvertCongenericScoreTrackToFormalMotifsBaseChain(tempTrack.CongenericScoreTracks[0], pauseTreatment, true);
                fmotifsAlphabet = FmotifRepository.GetOrCreateFmotifsInDb(fmotifsSequence.Alphabet);
                sequence.Id     = default;
                Create(sequence, fmotifsAlphabet, fmotifsSequence.Building, pauseTreatment, true);
            }
        }
        /// <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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SequenceImporter"/> class.
 /// </summary>
 /// <param name="db">
 /// The db.
 /// </param>
 protected SequenceImporter(LibiadaWebEntities db)
 {
     Db = db;
     MatterRepository = new MatterRepository(db);
     ElementRepository = new ElementRepository(db);
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SequenceImporter"/> class.
 /// </summary>
 /// <param name="db">
 /// The db.
 /// </param>
 protected SequenceImporter(LibiadaWebEntities db)
 {
     Db = db;
     MatterRepository  = new MatterRepository(db);
     ElementRepository = new ElementRepository(db);
 }