Esempio n. 1
0
        /// <summary>
        /// The fill parameters.
        /// </summary>
        /// <param name="fmotif">
        /// The Fmotif.
        /// </param>
        /// <param name="alphabet">
        /// The alphabet.
        /// </param>
        /// <param name="building">
        /// The building.
        /// </param>
        /// <returns>
        /// The <see cref="List{Object}"/>.
        /// </returns>
        protected List <NpgsqlParameter> FillParams(Fmotif fmotif, long[] alphabet, int[] building)
        {
            fmotif.Id = db.GetNewElementId();
            var fmotivValue = fmotif.GetHashCode().ToString();
            var parameters  = new List <NpgsqlParameter>
            {
                new NpgsqlParameter <long>("id", NpgsqlDbType.Bigint)
                {
                    TypedValue = fmotif.Id
                },
                new NpgsqlParameter <string>("value", NpgsqlDbType.Varchar)
                {
                    TypedValue = fmotivValue
                },
                new NpgsqlParameter <byte>("notation", NpgsqlDbType.Smallint)
                {
                    TypedValue = (byte)Notation.FormalMotifs
                },
                new NpgsqlParameter <long[]>("alphabet", NpgsqlDbType.Array | NpgsqlDbType.Bigint)
                {
                    TypedValue = alphabet
                },
                new NpgsqlParameter <int[]>("building", NpgsqlDbType.Array | NpgsqlDbType.Integer)
                {
                    TypedValue = building
                },
                new NpgsqlParameter <byte>("fmotif_type", NpgsqlDbType.Smallint)
                {
                    TypedValue = (byte)fmotif.Type
                }
            };

            return(parameters);
        }
        public void Create(ImageSequence sequence, LibiadaWebEntities db)
        {
            if (sequence.Id == default)
            {
                sequence.Id = db.GetNewElementId();
            }

            var parameters = new List <NpgsqlParameter>
            {
                new NpgsqlParameter <long>("id", NpgsqlDbType.Bigint)
                {
                    TypedValue = sequence.Id
                },
                new NpgsqlParameter <byte>("notation", NpgsqlDbType.Smallint)
                {
                    TypedValue = (byte)sequence.Notation
                },
                new NpgsqlParameter <long>("matter_id", NpgsqlDbType.Bigint)
                {
                    TypedValue = sequence.MatterId
                },
                new NpgsqlParameter <byte[]>("image_transformations", NpgsqlDbType.Array | NpgsqlDbType.Smallint)
                {
                    TypedValue = Array.Empty <byte>()
                },
                new NpgsqlParameter <byte[]>("matrix_transformations", NpgsqlDbType.Array | NpgsqlDbType.Smallint)
                {
                    TypedValue = Array.Empty <byte>()
                },
                new NpgsqlParameter <byte>("order_extractor", NpgsqlDbType.Smallint)
                {
                    TypedValue = (byte)sequence.OrderExtractor
                },
            };

            const string Query = @"INSERT INTO image_sequence (
                                        id,
                                        notation,
                                        matter_id,
                                        image_transformations,
                                        matrix_transformations,
                                        order_extractor
                                    ) VALUES (
                                        @id,
                                        @notation,
                                        @matter_id,
                                        @image_transformations,
                                        @matrix_transformations,
                                        @order_extractor
                                    );";

            db.ExecuteCommand(Query, parameters.ToArray());
        }
Esempio n. 3
0
        /// <summary>
        /// The fill parameters.
        /// </summary>
        /// <param name="measure">
        /// The measure.
        /// </param>
        /// <param name="alphabet">
        /// The alphabet.
        /// </param>
        /// <param name="building">
        /// The building.
        /// </param>
        /// <returns>
        /// The <see cref="List{Object}"/>.
        /// </returns>
        protected List <NpgsqlParameter> FillParams(Measure measure, long[] alphabet, int[] building)
        {
            measure.Id = db.GetNewElementId();
            var measureValue = measure.GetHashCode().ToString();
            var mode         = measure.Attributes.Key.Mode;

            var parameters = new List <NpgsqlParameter>
            {
                new NpgsqlParameter <long>("id", NpgsqlDbType.Bigint)
                {
                    TypedValue = measure.Id
                },
                new NpgsqlParameter <string>("value", NpgsqlDbType.Varchar)
                {
                    TypedValue = measureValue
                },
                new NpgsqlParameter <byte>("notation", NpgsqlDbType.Smallint)
                {
                    TypedValue = (byte)Notation.Measures
                },
                new NpgsqlParameter <long[]>("alphabet", NpgsqlDbType.Array | NpgsqlDbType.Bigint)
                {
                    TypedValue = alphabet
                },
                new NpgsqlParameter <int[]>("building", NpgsqlDbType.Array | NpgsqlDbType.Integer)
                {
                    TypedValue = building
                },
                new NpgsqlParameter <int>("beats", NpgsqlDbType.Integer)
                {
                    TypedValue = measure.Attributes.Size.Beats
                },
                new NpgsqlParameter <int>("beatbase", NpgsqlDbType.Integer)
                {
                    TypedValue = measure.Attributes.Size.BeatBase
                },
                new NpgsqlParameter <int>("fifths", NpgsqlDbType.Integer)
                {
                    TypedValue = measure.Attributes.Key.Fifths
                },
                new NpgsqlParameter <bool>("major", NpgsqlDbType.Boolean)
                {
                    TypedValue = (mode.Equals("major") || mode.Equals(null))
                }
            };

            return(parameters);
        }
Esempio n. 4
0
        /// <summary>
        /// The fill parameters.
        /// </summary>
        /// <param name="commonSequence">
        /// The sequence.
        /// </param>
        /// <param name="alphabet">
        /// The alphabet.
        /// </param>
        /// <param name="building">
        /// The building.
        /// </param>
        /// <returns>
        /// The <see cref="List{Object}"/>.
        /// </returns>
        protected List <NpgsqlParameter> FillParams(CommonSequence commonSequence, long[] alphabet, int[] building)
        {
            if (commonSequence.Id == default)
            {
                commonSequence.Id = Db.GetNewElementId();
            }

            var parameters = new List <NpgsqlParameter>
            {
                new NpgsqlParameter <long>("id", NpgsqlDbType.Bigint)
                {
                    TypedValue = commonSequence.Id
                },
                new NpgsqlParameter <byte>("notation", NpgsqlDbType.Smallint)
                {
                    TypedValue = (byte)commonSequence.Notation
                },
                new NpgsqlParameter <long>("matter_id", NpgsqlDbType.Bigint)
                {
                    TypedValue = commonSequence.MatterId
                },
                new NpgsqlParameter <long[]>("alphabet", NpgsqlDbType.Array | NpgsqlDbType.Bigint)
                {
                    TypedValue = alphabet
                },
                new NpgsqlParameter <int[]>("building", NpgsqlDbType.Array | NpgsqlDbType.Integer)
                {
                    TypedValue = building
                },
                new NpgsqlParameter <string>("remote_id", NpgsqlDbType.Varchar)
                {
                    TypedValue = commonSequence.RemoteId
                },
                new NpgsqlParameter("remote_db", NpgsqlDbType.Smallint)
                {
                    Value = (object)((byte?)commonSequence.RemoteDb) ?? DBNull.Value
                },
            };

            return(parameters);
        }
        /// <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());
        }