Esempio n. 1
0
    private void SpawnNextItem()
    {
        if (!QueueHasSpaceForNext())
        {
            return;
        }
        ItemData data = PopData();

        string root = "Gamer/";

        if (mover.isGamer)
        {
            root = "Gamer/";
        }
        else
        {
            root = "Comfy/";
        }
        GameObject item = Instantiate(Resources.Load(root + data.Label) as GameObject);

        item.transform.SetParent(ItemsGroup);
//        TextMesh text = item.GetComponentInChildren<TextMesh>();
//       text.text = data.Label;
        ItemScore score = item.GetComponentInChildren <ItemScore>();

        score.Joy     = data.Joy;
        score.Utility = data.Utility;
        Durability durability = item.GetComponentInChildren <Durability>();

        durability.Weight   = data.Width + data.Height;
        durability.Strength = data.Width * 5;
        enqueued.Add(item);
        drawQueue = true;
    }
Esempio n. 2
0
 public void OnMouseUp()
 {
     if (SelectedObject != null)
     {
         bool gravityActive = SelectedObject.GetComponent <GridMovement>().GravityActive;
         if (SafeToDrop && !gravityActive)       //actually drop item in truck
         {
             SelectedObject.SendMessage("Fall"); //tell object to fall
             ItemScore score = SelectedObject.GetComponentInChildren(typeof(ItemScore)) as ItemScore;
             score.state = ItemScore.State.OnTruck;
             itemQueue.RemoveFromQueue(SelectedObject);
             SelectedObject = null;//is no longer selected
             dropSnd.Play();
         }
         else if (SafeToTrash && !gravityActive)//drop item in trash
         {
             itemQueue.RemoveFromQueue(SelectedObject);
             TrashSnd.Play();
             SelectedObject.gameObject.GetComponentInChildren <SpriteRenderer>().enabled = false;
             Destroy(SelectedObject.gameObject, TrashSnd.clip.length);
             SelectedObject = null;//is no longer selected
         }
         else//item was dropped somewhere else on screen
         {
             //do something other than drop it
             //Back to selection thing?
             SelectedObject.position = OriginalPos;
             SelectedObject.GetComponent <BoxCollider2D>().enabled = true;
             SelectedObject = null;
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Method to merge higher-indexed item with new constructed contig.
        /// Merges consumed contig with new contig. For each sequence in consumed contig,
        /// compute sequence and offset to be added to new contig.
        /// </summary>
        /// <param name="newContig">New contig for merging</param>
        /// <param name="globalBest">Best Score, consensus, their offsets</param>
        /// <param name="consumedContig">Consumed Contig to be merged</param>
        private static void MergeHigherIndexedContig(Contig newContig, ItemScore globalBest, Contig consumedContig)
        {
            foreach (Contig.AssembledSequence aseq in consumedContig.Sequences)
            {
                Contig.AssembledSequence newASeq = new Contig.AssembledSequence();

                // as the higher-index item, this contig is never reversed or complemented, so:
                newASeq.IsReversed     = aseq.IsReversed;
                newASeq.IsComplemented = aseq.IsComplemented;

                // position in the new contig adjusted by alignment of the merged items.
                newASeq.Position = globalBest.SecondOffset + aseq.Position;
                newASeq.Sequence = SequenceWithoutTerminalGaps(aseq.Sequence);

                newContig.Sequences.Add(newASeq);
                if (Trace.Want(Trace.AssemblyDetails))
                {
                    ApplicationLog.WriteLine(
                        "\tseq (rev = {0} comp = {1} pos = {2}) {3}",
                        newASeq.IsReversed,
                        newASeq.IsComplemented,
                        newASeq.Position,
                        newASeq.Sequence);
                }
            }
        }
        public GradesPerTerm InitializeGrades(string term)
        {
            var gpt = new GradesPerTerm
            {
                Term  = term,
                Grade = 0
            };

            string[] types = { "Quiz1", "Quiz2", "Quiz3", "Assignment1", "Assignment2", "Assignment3" };

            var item = new ItemScore();

            for (int i = 0; i < types.Length; i++)
            {
                item = new ItemScore
                {
                    TotalItems = 0,
                    Score      = 0,
                    Grade      = 0,
                    Type       = types[i]
                };

                _appDbContext.Add(item);
                _appDbContext.SaveChanges();

                switch (i)
                {
                case 0:
                    gpt.Quiz1ID = item.ID;
                    break;

                case 1:
                    gpt.Quiz2ID = item.ID;
                    break;

                case 2:
                    gpt.Quiz3ID = item.ID;
                    break;

                case 3:
                    gpt.Assignment1ID = item.ID;
                    break;

                case 4:
                    gpt.Assignment2ID = item.ID;
                    break;

                case 5:
                    gpt.Assignment3ID = item.ID;
                    break;

                default:
                    break;
                }
            }

            return(gpt);
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the ItemScore struct
 /// copy constructor
 /// </summary>
 /// <param name="other">instance from which item score need to be copied</param>
 internal ItemScore(ItemScore other)
 {
     OtherItem    = other.OtherItem;
     OverlapScore = other.OverlapScore;
     Reversed     = other.Reversed;
     Complemented = other.Complemented;
     FirstOffset  = other.FirstOffset;
     SecondOffset = other.SecondOffset;
 }
Esempio n. 6
0
 public Score(ItemScore comments, ItemScore namingConventions, ItemScore unitTests, bool crash, int functionalErrors, int interfaceErrors)
 {
     this.Comments          = comments;
     this.NamingConventions = namingConventions;
     this.UnitTests         = unitTests;
     this.Crash             = crash;
     this.FunctionalErrors  = functionalErrors;
     this.InterfaceErrors   = interfaceErrors;
 }
Esempio n. 7
0
        public List <Movie> RecommendedMovies(int userId)
        {
            var consumerList = _context.UsersMovies.Where(um => um.UserId == userId).Include(um => um.Movie).ToList();
            List <Model.Movie> usersMovies = new List <Movie>();

            foreach (var movie in consumerList)
            {
                usersMovies.Add(_mapper.Map <Model.Movie>(movie.Movie));
            }
            var allMovies = _mapper.Map <List <Model.Movie> >(_context.Movies.ToList());

            foreach (var item in usersMovies)
            {
                allMovies.RemoveAll(m => m.MovieId == item.MovieId);
            }
            List <ItemScore <Model.Movie> > allMoviesWithScore = new List <ItemScore <Movie> >();

            foreach (var movie in allMovies)
            {
                ItemScore <Model.Movie> newItem = new ItemScore <Movie>()
                {
                    Item  = movie,
                    Score = 0
                };
                allMoviesWithScore.Add(newItem);
            }

            foreach (var movie in allMoviesWithScore)
            {
                foreach (var usersMovie in usersMovies)
                {
                    movie.Score += _similarity.CalculateSimilarity(_wordBagGenerator.GenerateWordBag <Model.Movie>(movie.Item), _wordBagGenerator.GenerateWordBag <Model.Movie>(usersMovie));
                }
            }

            allMoviesWithScore.Sort((a, b) => b.Score.CompareTo(a.Score));
            List <Model.Movie> recommendedMovies = new List <Movie>();

            foreach (var movie in allMoviesWithScore)
            {
                recommendedMovies.Add(movie.Item);
            }

            return(recommendedMovies);
        }
Esempio n. 8
0
        public List <Show> RecommendedShows(int userId)
        {
            var consumerList             = _context.UsersShows.Where(um => um.UserId == userId).Include(um => um.Show).ToList();
            List <Model.Show> usersShows = new List <Show>();

            foreach (var show in consumerList)
            {
                usersShows.Add(_mapper.Map <Model.Show>(show.Show));
            }
            var allShows = _mapper.Map <List <Model.Show> >(_context.Shows.ToList());

            foreach (var item in usersShows)
            {
                allShows.RemoveAll(m => m.ShowId == item.ShowId);
            }
            List <ItemScore <Model.Show> > allShowsWithScore = new List <ItemScore <Show> >();

            foreach (var show in allShows)
            {
                ItemScore <Model.Show> newItem = new ItemScore <Show>()
                {
                    Item  = show,
                    Score = 0
                };
                allShowsWithScore.Add(newItem);
            }

            foreach (var show in allShowsWithScore)
            {
                foreach (var usersShow in usersShows)
                {
                    show.Score += _similarity.CalculateSimilarity(_wordBagGenerator.GenerateWordBag <Model.Show>(show.Item), _wordBagGenerator.GenerateWordBag <Model.Show>(usersShow));
                }
            }

            allShowsWithScore.Sort((a, b) => b.Score.CompareTo(a.Score));
            List <Model.Show> recommendedShows = new List <Show>();

            foreach (var show in allShowsWithScore)
            {
                recommendedShows.Add(show.Item);
            }

            return(recommendedShows);
        }
Esempio n. 9
0
    void CheckCollisionsInBubble()
    {
        if (bubbleCollider2D.IsTouching(playerCollider2D))
        {
            for (int i = 0; i <= Random.Range(minItemScoreDropped, maxItemScoreDropped); i++)
            {
                ItemScore spawn = Instantiate(itemscorePrefab, transform.position,
                                              Quaternion.Euler(0, 0, Random.Range(0, 360)));

                Vector2 test = spawn.transform.up * Random.Range(minSpeedItemScore, maxSpeedItemScore);
                spawn.gameObject.GetComponent <Rigidbody2D>().velocity = test;
                Debug.DrawLine(transform.position, transform.position + (Vector3)test);
            }

            SoundManager.Instance.PlaySound(SoundManager.Sound.BUBBLE_POP);
            this.Die();
        }
    }
Esempio n. 10
0
        public ItemScore CalculateScore()
        {
            int       meetsMinimum = 0;
            ItemScore score        = (Crash) ? ItemScore.BelowStandard : ItemScore.MeetsMinimumStandard;

            ItemScore[] props = { Comments, NamingConventions, UnitTests, getItemScore(FunctionalErrors), getItemScore(InterfaceErrors) };
            // exit variable for the loop.
            // can be set to Crash because if crash it true, we don't need to loop
            // bool isBelowStandard = Crash;
            foreach (ItemScore el in props)
            {
                if (score == ItemScore.BelowStandard)
                {
                    break;
                }
                switch (el)
                {
                case ItemScore.MeetsMinimumStandard:
                    meetsMinimum++;
                    break;

                case ItemScore.BelowStandard:
                    score = ItemScore.BelowStandard;
                    break;
                }
            }
            if (score != ItemScore.BelowStandard)
            {
                if (meetsMinimum >= 3)
                {
                    score = ItemScore.BelowStandard;
                }
                else if (meetsMinimum == 2)
                {
                    score = ItemScore.MeetsMinimumStandard;
                }
                else
                {
                    score = ItemScore.MeetsStandard;
                }
            }
            return(score);
        }
Esempio n. 11
0
        /// <summary>
        /// Aligns the two input sequences, their reverseComplement, complement and reverse
        /// Keeps track of best score for these combinations.
        /// </summary>
        /// <param name="lowerIndexedSequence">Lower-indexed sequence to be aligned</param>
        /// <param name="higherIndexedSequence">Higher-indexed sequence to be aligned</param>
        /// <param name="lowerIndex">Index of first sequence in pool</param>
        /// <param name="higherIndex">Index of second sequence in pool</param>
        /// <returns>ItemScore containing score, consensus, offset of best alignment</returns>
        private ItemScore AlignSequence(ISequence lowerIndexedSequence, ISequence higherIndexedSequence, int lowerIndex, int higherIndex)
        {
            ItemScore bestScore = new ItemScore(lowerIndex, -1, false, false, 0, 0);

            bestScore = AlignAndUpdateBestScore(lowerIndexedSequence, higherIndexedSequence, false, false, bestScore, lowerIndex, higherIndex, "plain overlap of items");

            // Always try reverse complement
            bestScore = AlignAndUpdateBestScore(lowerIndexedSequence.ReverseComplement, higherIndexedSequence, true, true, bestScore, lowerIndex, higherIndex, "ReverseComplement overlap of items");

            if (!AssumeStandardOrientation)
            {
                // Reverse
                bestScore = AlignAndUpdateBestScore(lowerIndexedSequence.Reverse, higherIndexedSequence, true, false, bestScore, lowerIndex, higherIndex, "Reverse overlap of items");

                // Complement
                bestScore = AlignAndUpdateBestScore(lowerIndexedSequence.Complement, higherIndexedSequence, false, true, bestScore, lowerIndex, higherIndex, "Complement overlap of items");
            }

            return(bestScore);
        }
Esempio n. 12
0
        /// <summary>
        /// Aligns the two input sequences, their reverseComplement, complement and reverse
        /// Keeps track of best score for these combinations.
        /// </summary>
        /// <param name="lowerIndexedSequence">Lower-indexed sequence to be aligned</param>
        /// <param name="higherIndexedSequence">Higher-indexed sequence to be aligned</param>
        /// <param name="lowerIndex">Index of first sequence in pool</param>
        /// <param name="higherIndex">Index of second sequence in pool</param>
        /// <returns>ItemScore containing score, consensus, offset of best alignment</returns>
        private ItemScore AlignSequence(ISequence lowerIndexedSequence, ISequence higherIndexedSequence, int lowerIndex, int higherIndex)
        {
            ItemScore bestScore = new ItemScore(lowerIndex, -1, false, false, 0, 0);

            bestScore = AlignAndUpdateBestScore(lowerIndexedSequence, higherIndexedSequence, false, false, bestScore, lowerIndex, higherIndex, Properties.Resource.MsgPlainOverlapItems);

            // Always try reverse complement
            bestScore = AlignAndUpdateBestScore(lowerIndexedSequence.GetReverseComplementedSequence(), higherIndexedSequence, true, true, bestScore, lowerIndex, higherIndex, Properties.Resource.MsgReverseComplementOverlapItems);

            if (!AssumeStandardOrientation)
            {
                // Reverse
                bestScore = AlignAndUpdateBestScore(lowerIndexedSequence.GetReversedSequence(), higherIndexedSequence, true, false, bestScore, lowerIndex, higherIndex, Properties.Resource.MsgReverseOverlapItems);

                // Complement
                bestScore = AlignAndUpdateBestScore(lowerIndexedSequence.GetComplementedSequence(), higherIndexedSequence, false, true, bestScore, lowerIndex, higherIndex, Properties.Resource.MsgComplementOverlapItems);
            }

            return(bestScore);
        }
Esempio n. 13
0
        /// <summary>
        /// Method to merge higher-indexed item with new constructed contig.
        /// Merges consumed sequence with new contig. For the consumed sequence,
        /// compute new sequence and offset to be added to new contig.
        /// </summary>
        /// <param name="newContig">New contig for merging</param>
        /// <param name="globalBest">Best Score, consensus, their offsets</param>
        /// <param name="consumedSequence">Consumed Sequence to be merged</param>
        private static void MergeHigherIndexedSequence(Contig newContig, ItemScore globalBest, ISequence consumedSequence)
        {
            Contig.AssembledSequence newASeq = new Contig.AssembledSequence();

            // as the higher-index item, this sequence is never reversed or complemented, so:
            newASeq.IsReversed     = false;
            newASeq.IsComplemented = false;
            newASeq.Position       = globalBest.SecondOffset;
            newASeq.Sequence       = SequenceWithoutTerminalGaps(consumedSequence);

            newContig.Sequences.Add(newASeq);
            if (Trace.Want(Trace.AssemblyDetails))
            {
                ApplicationLog.WriteLine(
                    "seq (rev = {0} comp = {1} pos = {2}) {3}",
                    newASeq.IsReversed,
                    newASeq.IsComplemented,
                    newASeq.Position,
                    newASeq.Sequence);
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Method to merge lower-indexed item with new constructed contig
        /// Merges consumed sequence with new contig. For the consumed sequence,
        /// compute new sequence and offset to be added to new contig.
        /// </summary>
        /// <param name="newContig">New contig for merging</param>
        /// <param name="globalBest">Best Score, consensus, their offsets</param>
        /// <param name="consumedSequence">Consumed Sequence to be merged</param>
        private static void MergeLowerIndexedSequence(Contig newContig, ItemScore globalBest, ISequence consumedSequence)
        {
            Contig.AssembledSequence newASeq = new Contig.AssembledSequence();

            // lower-indexed item might be reversed or complemented.
            // Retreive information from globalBest
            newASeq.IsReversed     = globalBest.Reversed;
            newASeq.IsComplemented = globalBest.Complemented;
            newASeq.Position       = globalBest.FirstOffset;
            newASeq.Sequence       = SequenceWithoutTerminalGaps(consumedSequence);

            newContig.Sequences.Add(newASeq);
            if (Trace.Want(Trace.AssemblyDetails))
            {
                ApplicationLog.WriteLine(
                    "seq (rev = {0} comp = {1} pos = {2}) {3}",
                    newASeq.IsReversed,
                    newASeq.IsComplemented,
                    newASeq.Position,
                    newASeq.Sequence);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Method to merge lower-indexed item with new constructed contig.
        /// Merges consumed contig with new contig. For each sequence in consumed contig,
        /// compute sequence and offset to be added to new contig.
        /// </summary>
        /// <param name="newContig">New contig for merging</param>
        /// <param name="globalBest">Best Score along with offsets information</param>
        /// <param name="consumedContig">Contig to be merged</param>
        private static void MergeLowerIndexedContig(Contig newContig, ItemScore globalBest, Contig consumedContig)
        {
            foreach (Contig.AssembledSequence aseq in consumedContig.Sequences)
            {
                Contig.AssembledSequence newASeq = new Contig.AssembledSequence();

                // lower-indexed item might be reversed or complemented.
                // Construct new sequence based on setting in globalBest
                // reverse of reverse, or comp of comp, equals no-op. So use xor
                newASeq.IsReversed     = aseq.IsReversed ^ globalBest.Reversed;
                newASeq.IsComplemented = aseq.IsComplemented ^ globalBest.Complemented;

                // position in the new contig is adjusted by alignment of the merged items.
                // this depends on whether the contig is reverse-aligned.
                if (globalBest.Reversed)
                {
                    long rightOffset = consumedContig.Length - (aseq.Sequence.Count + aseq.Position);
                    newASeq.Position = globalBest.FirstOffset + rightOffset;
                }
                else
                {
                    newASeq.Position = globalBest.FirstOffset + aseq.Position;
                }

                newASeq.Sequence = SequenceWithoutTerminalGaps(aseq.Sequence);
                newContig.Sequences.Add(newASeq);
                if (Trace.Want(Trace.AssemblyDetails))
                {
                    ApplicationLog.WriteLine(
                        "\tseq (rev = {0} comp = {1} pos = {2}) {3}",
                        newASeq.IsReversed,
                        newASeq.IsComplemented,
                        newASeq.Position,
                        newASeq.Sequence);
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Assemble the input sequences into the largest possible contigs.
        /// </summary>
        /// <remarks>
        /// The algorithm is:
        /// 1.  initialize list of contigs to empty list. List of seqs is passed as argument.
        /// 2.  compute pairwise overlap scores for each pair of input seqs (with reversal and
        ///     complementation as appropriate).
        /// 3.  choose best overlap score. the “merge items” (can be seqs or contigs) are the
        ///     items with that score. If best score is less than threshold, assembly is finished.
        /// 4.  merge the merge items into a single contig and remove them from their list(s)
        /// 5.  compute the overlap between new item and all existing items
        /// 6.  go to step 3
        /// </remarks>
        /// <param name="inputSequences">The sequences to assemble.</param>
        /// <returns>Returns the OverlapDeNovoAssembly instance which contains list of
        /// contigs and list of unmerged sequences which are result of this assembly.</returns>
        public IDeNovoAssembly Assemble(IEnumerable <ISequence> inputSequences)
        {
            if (null == inputSequences)
            {
                throw new ArgumentNullException(Properties.Resource.ParameterNameInputSequences);
            }

            // Initializations
            if (inputSequences.Count() > 0)
            {
                _sequenceAlphabet = inputSequences.First().Alphabet;

                if (ConsensusResolver == null)
                {
                    ConsensusResolver = new SimpleConsensusResolver(_sequenceAlphabet);
                }
                else
                {
                    ConsensusResolver.SequenceAlphabet = _sequenceAlphabet;
                }
            }

            OverlapDeNovoAssembly sequenceAssembly = null;

            // numbering convention: every pool item (whether sequence or contig)
            // gets a fixed number.
            // sequence index = index into inputs (which we won't modify)
            // contig index = nSequences + index into contigs
            List <PoolItem> pool = new List <PoolItem>();

            foreach (ISequence seq in inputSequences)
            {
                pool.Add(new PoolItem(seq));
            }

            // put all the initial sequences into the pool, and generate the pair scores.
            // there are no contigs in the pool yet.
            // to save an iteration, we'll also find the best global score as we go.
            ItemScore globalBest            = new ItemScore(-1, -1, false, false, 0, 0);
            int       globalBestLargerIndex = -1;
            int       unconsumedCount       = inputSequences.Count();

            // Compute alignment scores for all combinations between input sequences
            // Store these scores in the poolItem correspodning to each sequence
            for (int newSeq = 0; newSeq < pool.Count; ++newSeq)
            {
                PoolItem newItem = pool[newSeq];
                for (int oldSeq = 0; oldSeq < newSeq; ++oldSeq)
                {
                    PoolItem  oldItem = pool[oldSeq];
                    ItemScore score   = AlignSequence(oldItem.SequenceOrConsensus, newItem.SequenceOrConsensus, oldSeq, newSeq);
                    newItem.Scores.Add(score);
                    if (score.OverlapScore > globalBest.OverlapScore)
                    {
                        globalBest            = new ItemScore(score);
                        globalBestLargerIndex = newSeq;
                    }
                }
            }

            // Merge sequence if best score is above threshold
            // and add new contig to pool
            if (globalBest.OverlapScore >= MergeThreshold)
            {
                if (Trace.Want(Trace.AssemblyDetails))
                {
                    ApplicationLog.WriteLine("Merging (overlap score {0}):", globalBest.OverlapScore);
                }

                PoolItem mergeItem1 = pool[globalBest.OtherItem];
                PoolItem mergeItem2 = pool[globalBestLargerIndex];
                Contig   newContig  = new Contig();
                if (Trace.Want(Trace.AssemblyDetails))
                {
                    ApplicationLog.WriteLine(
                        "new pool item {0} will merge old items {1} and {2}",
                        pool.Count,
                        globalBest.OtherItem,
                        globalBestLargerIndex);
                }

                MergeLowerIndexedSequence(newContig, globalBest, mergeItem1.Sequence);
                MergeHigherIndexedSequence(newContig, globalBest, mergeItem2.Sequence);

                MakeConsensus(newContig);

                // Set ConsumedBy value and
                // free memory as these sequences are no longer used
                mergeItem1.ConsumedBy = pool.Count;
                mergeItem2.ConsumedBy = pool.Count;
                mergeItem1.FreeSequences();
                mergeItem2.FreeSequences();
                pool.Add(new PoolItem(newContig));
                unconsumedCount--;

                while (unconsumedCount > 1)
                {
                    // Compute scores for each unconsumed sequence with new contig
                    globalBest            = new ItemScore(-1, -1, false, false, 0, 0);
                    globalBestLargerIndex = -1;
                    int      newSeq  = pool.Count - 1;
                    PoolItem newItem = pool[newSeq];
                    for (int oldSeq = 0; oldSeq < pool.Count - 1; ++oldSeq)
                    {
                        PoolItem oldItem = pool[oldSeq];
                        if (oldItem.ConsumedBy >= 0)
                        {
                            // already consumed - just add dummy score to maintain correct indices
                            newItem.Scores.Add(new ItemScore());
                        }
                        else
                        {
                            ItemScore score = AlignSequence(oldItem.SequenceOrConsensus, newItem.SequenceOrConsensus, oldSeq, newSeq);
                            newItem.Scores.Add(score);
                        }
                    }

                    // find best global score in the modified pool.
                    globalBest            = new ItemScore(-1, -1, false, false, 0, 0);
                    globalBestLargerIndex = -1;
                    for (int current = 0; current < pool.Count; ++current)
                    {
                        PoolItem curItem = pool[current];
                        if (curItem.ConsumedBy < 0)
                        {
                            for (int other = 0; other < current; ++other)
                            {
                                if (pool[other].ConsumedBy < 0)
                                {
                                    ItemScore itemScore = curItem.Scores[other];
                                    if (itemScore.OverlapScore > globalBest.OverlapScore)
                                    {
                                        globalBest            = new ItemScore(itemScore); // copy the winner so far
                                        globalBestLargerIndex = current;
                                    }
                                }
                            }
                        }
                    }

                    if (globalBest.OverlapScore >= MergeThreshold)
                    {
                        // Merge sequences / contigs if above threshold
                        mergeItem1 = pool[globalBest.OtherItem];
                        mergeItem2 = pool[globalBestLargerIndex];
                        newContig  = new Contig();

                        if (mergeItem1.IsContig)
                        {
                            if (Trace.Want(Trace.AssemblyDetails))
                            {
                                ApplicationLog.WriteLine(
                                    "item {0} is a contig (reversed = {1}, complemented = {2}, offset = {3}",
                                    globalBest.OtherItem,
                                    globalBest.Reversed,
                                    globalBest.Complemented,
                                    globalBest.FirstOffset);
                            }

                            MergeLowerIndexedContig(newContig, globalBest, mergeItem1.Contig);
                        }
                        else
                        {
                            if (Trace.Want(Trace.AssemblyDetails))
                            {
                                ApplicationLog.WriteLine(
                                    "item {0} is a sequence (reversed = {1}, complemented = {2}, offset = {3}",
                                    globalBest.OtherItem,
                                    globalBest.Reversed,
                                    globalBest.Complemented,
                                    globalBest.FirstOffset);
                            }

                            MergeLowerIndexedSequence(newContig, globalBest, mergeItem1.Sequence);
                        }

                        if (mergeItem2.IsContig)
                        {
                            if (Trace.Want(Trace.AssemblyDetails))
                            {
                                ApplicationLog.WriteLine(
                                    "item {0} is a contig (offset = {1}",
                                    globalBestLargerIndex,
                                    globalBest.SecondOffset);
                            }

                            MergeHigherIndexedContig(newContig, globalBest, mergeItem2.Contig);
                        }
                        else
                        {
                            if (Trace.Want(Trace.AssemblyDetails))
                            {
                                ApplicationLog.WriteLine(
                                    "item {0} is a sequence (offset = {1}",
                                    globalBestLargerIndex,
                                    globalBest.SecondOffset);
                            }

                            MergeHigherIndexedSequence(newContig, globalBest, mergeItem2.Sequence);
                        }

                        MakeConsensus(newContig);
                        if (Trace.Want(Trace.AssemblyDetails))
                        {
                            Dump(newContig);
                        }

                        // Set ConsumedBy value for these poolItems and
                        // free memory as these sequences are no longer used
                        mergeItem1.ConsumedBy = pool.Count;
                        mergeItem2.ConsumedBy = pool.Count;
                        mergeItem1.FreeSequences();
                        mergeItem2.FreeSequences();

                        pool.Add(new PoolItem(newContig));
                        unconsumedCount--;
                    }
                    else
                    {
                        // None of the alignment scores cross threshold
                        // No more merges possible. So end iteration.
                        break;
                    }
                }
            }

            // no further qualifying merges, so we're done.
            // populate contigs and unmergedSequences
            sequenceAssembly = new OverlapDeNovoAssembly();
            foreach (PoolItem curItem in pool)
            {
                if (curItem.ConsumedBy < 0)
                {
                    if (curItem.IsContig)
                    {
                        sequenceAssembly.Contigs.Add(curItem.Contig);
                    }
                    else
                    {
                        sequenceAssembly.UnmergedSequences.Add(curItem.Sequence);
                    }
                }
            }

            return(sequenceAssembly);
        }
Esempio n. 17
0
        /// <summary>
        /// Method to merge lower-indexed item with new constructed contig.
        /// Merges consumed contig with new contig. For each sequence in consumed contig, 
        /// compute sequence and offset to be added to new contig.
        /// </summary>
        /// <param name="newContig">New contig for merging</param>
        /// <param name="globalBest">Best Score along with offsets information</param>
        /// <param name="consumedContig">Contig to be merged</param>
        private static void MergeLowerIndexedContig(Contig newContig, ItemScore globalBest, Contig consumedContig)
        {
            foreach (Contig.AssembledSequence aseq in consumedContig.Sequences)
            {
                Contig.AssembledSequence newASeq = new Contig.AssembledSequence();

                // lower-indexed item might be reversed or complemented. 
                // Construct new sequence based on setting in globalBest
                // reverse of reverse, or comp of comp, equals no-op. So use xor
                newASeq.IsReversed = aseq.IsReversed ^ globalBest.Reversed;
                newASeq.IsComplemented = aseq.IsComplemented ^ globalBest.Complemented;

                // position in the new contig is adjusted by alignment of the merged items.
                // this depends on whether the contig is reverse-aligned.
                if (globalBest.Reversed)
                {
                    long rightOffset = consumedContig.Length - (aseq.Sequence.Count + aseq.Position);
                    newASeq.Position = globalBest.FirstOffset + rightOffset;
                }
                else
                {
                    newASeq.Position = globalBest.FirstOffset + aseq.Position;
                }

                newASeq.Sequence = SequenceWithoutTerminalGaps(aseq.Sequence);
                newContig.Sequences.Add(newASeq);
                if (Trace.Want(Trace.AssemblyDetails))
                {
                    ApplicationLog.WriteLine(
                        "\tseq (rev = {0} comp = {1} pos = {2}) {3}",
                        newASeq.IsReversed,
                        newASeq.IsComplemented,
                        newASeq.Position,
                        newASeq.Sequence);
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Aligns the two input sequence
        /// Updates best score, if necessary
        /// </summary>
        /// <param name="sequence1">First Sequence to be aligned</param>
        /// <param name="sequence2">Second Sequence to be aligned</param>
        /// <param name="reversed">Is first sequence reversed?</param>
        /// <param name="complement">Is first sequence complemented?</param>
        /// <param name="bestScore">Structure to track best score</param>
        /// <param name="sequence1PoolIndex">Index of first sequence in pool.
        /// Used in printing for debug purpose.</param>
        /// <param name="sequence2PoolIndex">Index of second sequence in pool.
        /// Used in printing for debug purpose.</param>
        /// <param name="message">Message to be printed for debug purpose</param>
        /// <returns>Updated best score</returns>
        private ItemScore AlignAndUpdateBestScore(
            ISequence sequence1,
            ISequence sequence2,
            bool reversed,
            bool complement,
            ItemScore bestScore,
            int sequence1PoolIndex,
            int sequence2PoolIndex,
            string message)
        {
            // we will look for the best (largest) overlap score. Note that
            // lower-index items are already in place, so can do this in same pass
            IList<ISequenceAlignment> alignment = RunAlignSimple(sequence1, sequence2);
            if (Trace.Want(Trace.AssemblyDetails))
            {
                ApplicationLog.WriteLine("{0} {1} and {2}", message, sequence1PoolIndex, sequence2PoolIndex);
                Dump(alignment);
            }

            if (alignment.Count > 0 &&
                alignment[0].AlignedSequences.Count > 0)
            {
                long score = 0;
                if (alignment[0].AlignedSequences[0].Metadata.ContainsKey("Score"))
                {
                    try
                    {
                        score = (long) alignment[0].AlignedSequences[0].Metadata["Score"];
                    }
                    catch
                    {
                        // no impl.
                    }
                }

                if (score > bestScore.OverlapScore)
                {
                    bestScore.OverlapScore = score;
                    bestScore.Reversed = reversed;
                    bestScore.Complemented = complement;

                    long offsets = 0;
                    if (alignment[0].AlignedSequences[0].Metadata.ContainsKey("FirstOffset"))
                    {
                        try
                        {
                            offsets = (long) alignment[0].AlignedSequences[0].Metadata["FirstOffset"];
                        }
                        catch
                        {
                            // no impl.
                        }
                    }

                    bestScore.FirstOffset = offsets;
                    offsets = 0;
                    if (alignment[0].AlignedSequences[0].Metadata.ContainsKey("SecondOffset"))
                    {
                        try
                        {
                            offsets = (long) alignment[0].AlignedSequences[0].Metadata["SecondOffset"];
                        }
                        catch
                        {
                            // no impl.
                        }
                    }

                    bestScore.SecondOffset = offsets;
                }
            }

            return bestScore;
        }
Esempio n. 19
0
 /// <summary>
 /// Initializes a new instance of the ItemScore struct
 /// copy constructor
 /// </summary>
 /// <param name="other">instance from which item score need to be copied</param>
 internal ItemScore(ItemScore other)
 {
     OtherItem = other.OtherItem;
     OverlapScore = other.OverlapScore;
     Reversed = other.Reversed;
     Complemented = other.Complemented;
     FirstOffset = other.FirstOffset;
     SecondOffset = other.SecondOffset;
 }
Esempio n. 20
0
        /// <summary>
        /// Method to merge higher-indexed item with new constructed contig.
        /// Merges consumed sequence with new contig. For the consumed sequence,
        /// compute new sequence and offset to be added to new contig.
        /// </summary>
        /// <param name="newContig">New contig for merging</param>
        /// <param name="globalBest">Best Score, consensus, their offsets</param>
        /// <param name="consumedSequence">Consumed Sequence to be merged</param>
        private static void MergeHigherIndexedSequence(Contig newContig, ItemScore globalBest, ISequence consumedSequence)
        {
            Contig.AssembledSequence newASeq = new Contig.AssembledSequence();

            // as the higher-index item, this sequence is never reversed or complemented, so:
            newASeq.IsReversed = false;
            newASeq.IsComplemented = false;
            newASeq.Position = globalBest.SecondOffset;
            newASeq.Sequence = SequenceWithoutTerminalGaps(consumedSequence);

            newContig.Sequences.Add(newASeq);
            if (Trace.Want(Trace.AssemblyDetails))
            {
                ApplicationLog.WriteLine(
                    "seq (rev = {0} comp = {1} pos = {2}) {3}",
                    newASeq.IsReversed,
                    newASeq.IsComplemented,
                    newASeq.Position,
                    newASeq.Sequence);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Aligns the two input sequences, their reverseComplement, complement and reverse
        /// Keeps track of best score for these combinations.
        /// </summary>
        /// <param name="lowerIndexedSequence">Lower-indexed sequence to be aligned</param>
        /// <param name="higherIndexedSequence">Higher-indexed sequence to be aligned</param>
        /// <param name="lowerIndex">Index of first sequence in pool</param>
        /// <param name="higherIndex">Index of second sequence in pool</param>
        /// <returns>ItemScore containing score, consensus, offset of best alignment</returns>
        private ItemScore AlignSequence(ISequence lowerIndexedSequence, ISequence higherIndexedSequence, int lowerIndex, int higherIndex)
        {
            ItemScore bestScore = new ItemScore(lowerIndex, -1, false, false, 0, 0);
            bestScore = AlignAndUpdateBestScore(lowerIndexedSequence, higherIndexedSequence, false, false, bestScore, lowerIndex, higherIndex, Properties.Resource.MsgPlainOverlapItems);

            // Always try reverse complement
            bestScore = AlignAndUpdateBestScore(lowerIndexedSequence.GetReverseComplementedSequence(), higherIndexedSequence, true, true, bestScore, lowerIndex, higherIndex, Properties.Resource.MsgReverseComplementOverlapItems);

            if (!AssumeStandardOrientation)
            {
                // Reverse
                bestScore = AlignAndUpdateBestScore(lowerIndexedSequence.GetReversedSequence(), higherIndexedSequence, true, false, bestScore, lowerIndex, higherIndex, Properties.Resource.MsgReverseOverlapItems);

                // Complement
                bestScore = AlignAndUpdateBestScore(lowerIndexedSequence.GetComplementedSequence(), higherIndexedSequence, false, true, bestScore, lowerIndex, higherIndex, Properties.Resource.MsgComplementOverlapItems);
            }

            return bestScore;
        }
Esempio n. 22
0
        /// <summary>
        /// Method to merge higher-indexed item with new constructed contig.
        /// Merges consumed contig with new contig. For each sequence in consumed contig, 
        /// compute sequence and offset to be added to new contig.
        /// </summary>
        /// <param name="newContig">New contig for merging</param>
        /// <param name="globalBest">Best Score, consensus, their offsets</param>
        /// <param name="consumedContig">Consumed Contig to be merged</param>
        private static void MergeHigherIndexedContig(Contig newContig, ItemScore globalBest, Contig consumedContig)
        {
            foreach (Contig.AssembledSequence aseq in consumedContig.Sequences)
            {
                Contig.AssembledSequence newASeq = new Contig.AssembledSequence();

                // as the higher-index item, this contig is never reversed or complemented, so:
                newASeq.IsReversed = aseq.IsReversed;
                newASeq.IsComplemented = aseq.IsComplemented;

                // position in the new contig adjusted by alignment of the merged items.
                newASeq.Position = globalBest.SecondOffset + aseq.Position;
                newASeq.Sequence = SequenceWithoutTerminalGaps(aseq.Sequence);

                newContig.Sequences.Add(newASeq);
                if (Trace.Want(Trace.AssemblyDetails))
                {
                    ApplicationLog.WriteLine(
                        "\tseq (rev = {0} comp = {1} pos = {2}) {3}",
                        newASeq.IsReversed,
                        newASeq.IsComplemented,
                        newASeq.Position,
                        newASeq.Sequence);
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Method to merge lower-indexed item with new constructed contig
        /// Merges consumed sequence with new contig. For the consumed sequence,
        /// compute new sequence and offset to be added to new contig.
        /// </summary>
        /// <param name="newContig">New contig for merging</param>
        /// <param name="globalBest">Best Score, consensus, their offsets</param>
        /// <param name="consumedSequence">Consumed Sequence to be merged</param>
        private static void MergeLowerIndexedSequence(Contig newContig, ItemScore globalBest, ISequence consumedSequence)
        {
            Contig.AssembledSequence newASeq = new Contig.AssembledSequence();

            // lower-indexed item might be reversed or complemented. 
            // Retreive information from globalBest
            newASeq.IsReversed = globalBest.Reversed;
            newASeq.IsComplemented = globalBest.Complemented;
            newASeq.Position = globalBest.FirstOffset;
            newASeq.Sequence = SequenceWithoutTerminalGaps(consumedSequence);

            newContig.Sequences.Add(newASeq);
            if (Trace.Want(Trace.AssemblyDetails))
            {
                ApplicationLog.WriteLine(
                    "seq (rev = {0} comp = {1} pos = {2}) {3}",
                    newASeq.IsReversed,
                    newASeq.IsComplemented,
                    newASeq.Position,
                    newASeq.Sequence);
            }
        }
        public async Task <IActionResult> AddGrade(int id, ItemScore itemScore)
        {
            if (id != itemScore.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                double rawGrade = Convert.ToDouble(itemScore.Score) / Convert.ToDouble(itemScore.TotalItems);
                itemScore.Grade = Math.Round(rawGrade, 2);
                if (itemScore.Type == "Quiz1")
                {
                    var term = await _db.GradesPerTerms.FirstOrDefaultAsync(
                        i => i.Quiz1ID == itemScore.ID);

                    _db.Update(term);
                }
                else if (itemScore.Type == "Quiz2")
                {
                    var term = await _db.GradesPerTerms.FirstOrDefaultAsync(
                        i => i.Quiz2ID == itemScore.ID);

                    _db.Update(term);
                }
                else if (itemScore.Type == "Quiz3")
                {
                    var term = await _db.GradesPerTerms.FirstOrDefaultAsync(
                        i => i.Quiz3ID == itemScore.ID);

                    _db.Update(term);
                }
                else if (itemScore.Type == "Assignment1")
                {
                    var term = await _db.GradesPerTerms.FirstOrDefaultAsync(
                        i => i.Assignment1ID == itemScore.ID);

                    _db.Update(term);
                }
                else if (itemScore.Type == "Assignment2")
                {
                    var term = await _db.GradesPerTerms.FirstOrDefaultAsync(
                        i => i.Assignment2ID == itemScore.ID);

                    _db.Update(term);
                }
                else if (itemScore.Type == "Assignment3")
                {
                    var term = await _db.GradesPerTerms.FirstOrDefaultAsync(
                        i => i.Assignment3ID == itemScore.ID);

                    _db.Update(term);
                }

                _db.Update(itemScore);
                await _db.SaveChangesAsync();

                return(RedirectToAction("StudentList"));
            }

            return(View());
        }
Esempio n. 25
0
        /// <summary>
        /// Assemble the input sequences into the largest possible contigs. 
        /// </summary>
        /// <remarks>
        /// The algorithm is:
        /// 1.  initialize list of contigs to empty list. List of seqs is passed as argument.
        /// 2.  compute pairwise overlap scores for each pair of input seqs (with reversal and
        ///     complementation as appropriate).
        /// 3.  choose best overlap score. the “merge items” (can be seqs or contigs) are the 
        ///     items with that score. If best score is less than threshold, assembly is finished.
        /// 4.  merge the merge items into a single contig and remove them from their list(s)
        /// 5.  compute the overlap between new item and all existing items
        /// 6.  go to step 3
        /// </remarks>
        /// <param name="inputSequences">The sequences to assemble.</param>
        /// <returns>Returns the OverlapDeNovoAssembly instance which contains list of 
        /// contigs and list of unmerged sequences which are result of this assembly.</returns>
        public IDeNovoAssembly Assemble(IEnumerable<ISequence> inputSequences)
        {
            if (null == inputSequences)
            {
                throw new ArgumentNullException(Properties.Resource.ParameterNameInputSequences);
            }

            // numbering convention: every pool item (whether sequence or contig)
            // gets a fixed number.
            // sequence index = index into inputs (which we won't modify)
            // contig index = nSequences + index into contigs
            List<PoolItem> pool = inputSequences.Select(seq => new PoolItem(seq)).ToList();

            // Initialization
            int sequenceCount = pool.Count;
            if (sequenceCount > 0)
            {
                _sequenceAlphabet = pool[0].Sequence.Alphabet;

                if (ConsensusResolver == null)
                {
                    ConsensusResolver = new SimpleConsensusResolver(_sequenceAlphabet);
                }
                else
                {
                    ConsensusResolver.SequenceAlphabet = _sequenceAlphabet;
                }
            }

            // put all the initial sequences into the pool, and generate the pair scores.
            // there are no contigs in the pool yet.
            // to save an iteration, we'll also find the best global score as we go.
            ItemScore globalBest = new ItemScore(-1, -1, false, false, 0, 0);
            int globalBestLargerIndex = -1;
            int unconsumedCount = sequenceCount;

            // Compute alignment scores for all combinations between input sequences
            // Store these scores in the poolItem corresponding to each sequence
            for (int newSeq = 0; newSeq < pool.Count; ++newSeq)
            {
                PoolItem newItem = pool[newSeq];
                for (int oldSeq = 0; oldSeq < newSeq; ++oldSeq)
                {
                    PoolItem oldItem = pool[oldSeq];
                    ItemScore score = AlignSequence(oldItem.SequenceOrConsensus, newItem.SequenceOrConsensus, oldSeq, newSeq);
                    newItem.Scores.Add(score);
                    if (score.OverlapScore > globalBest.OverlapScore)
                    {
                        globalBest = new ItemScore(score);
                        globalBestLargerIndex = newSeq;
                    }
                }
            }

            // Merge sequence if best score is above threshold 
            // and add new contig to pool
            if (globalBest.OverlapScore >= MergeThreshold)
            {
                if (Trace.Want(Trace.AssemblyDetails))
                {
                    ApplicationLog.WriteLine("Merging (overlap score {0}):", globalBest.OverlapScore);
                }

                PoolItem mergeItem1 = pool[globalBest.OtherItem];
                PoolItem mergeItem2 = pool[globalBestLargerIndex];
                Contig newContig = new Contig();
                if (Trace.Want(Trace.AssemblyDetails))
                {
                    ApplicationLog.WriteLine(
                        "new pool item {0} will merge old items {1} and {2}",
                        pool.Count,
                        globalBest.OtherItem,
                        globalBestLargerIndex);
                }

                MergeLowerIndexedSequence(newContig, globalBest, mergeItem1.Sequence);
                MergeHigherIndexedSequence(newContig, globalBest, mergeItem2.Sequence);
                MakeConsensus(newContig);

                // Set ConsumedBy value and 
                // free memory as these sequences are no longer used
                mergeItem1.ConsumedBy = pool.Count;
                mergeItem2.ConsumedBy = pool.Count;
                mergeItem1.FreeSequences();
                mergeItem2.FreeSequences();
                pool.Add(new PoolItem(newContig));
                unconsumedCount--;

                while (unconsumedCount > 1)
                {
                    // Compute scores for each unconsumed sequence with new contig
                    int newSeq = pool.Count - 1;
                    PoolItem newItem = pool[newSeq];
                    for (int oldSeq = 0; oldSeq < pool.Count - 1; ++oldSeq)
                    {
                        PoolItem oldItem = pool[oldSeq];
                        if (oldItem.ConsumedBy >= 0)
                        {
                            // already consumed - just add dummy score to maintain correct indices
                            newItem.Scores.Add(new ItemScore());
                        }
                        else
                        {
                            ItemScore score = AlignSequence(oldItem.SequenceOrConsensus, newItem.SequenceOrConsensus, oldSeq, newSeq);
                            newItem.Scores.Add(score);
                        }
                    }

                    // find best global score in the modified pool.
                    globalBest = new ItemScore(-1, -1, false, false, 0, 0);
                    globalBestLargerIndex = -1;
                    for (int current = 0; current < pool.Count; ++current)
                    {
                        PoolItem curItem = pool[current];
                        if (curItem.ConsumedBy < 0)
                        {
                            for (int other = 0; other < current; ++other)
                            {
                                if (pool[other].ConsumedBy < 0)
                                {
                                    ItemScore itemScore = curItem.Scores[other];
                                    if (itemScore.OverlapScore > globalBest.OverlapScore)
                                    {
                                        globalBest = new ItemScore(itemScore);  // copy the winner so far
                                        globalBestLargerIndex = current;
                                    }
                                }
                            }
                        }
                    }

                    if (globalBest.OverlapScore >= MergeThreshold)
                    {
                        // Merge sequences / contigs if above threshold
                        mergeItem1 = pool[globalBest.OtherItem];
                        mergeItem2 = pool[globalBestLargerIndex];
                        newContig = new Contig();

                        if (mergeItem1.IsContig)
                        {
                            if (Trace.Want(Trace.AssemblyDetails))
                            {
                                ApplicationLog.WriteLine(
                                    "item {0} is a contig (reversed = {1}, complemented = {2}, offset = {3}",
                                    globalBest.OtherItem,
                                    globalBest.Reversed,
                                    globalBest.Complemented,
                                    globalBest.FirstOffset);
                            }

                            MergeLowerIndexedContig(newContig, globalBest, mergeItem1.Contig);
                        }
                        else
                        {
                            if (Trace.Want(Trace.AssemblyDetails))
                            {
                                ApplicationLog.WriteLine(
                                    "item {0} is a sequence (reversed = {1}, complemented = {2}, offset = {3}",
                                    globalBest.OtherItem,
                                    globalBest.Reversed,
                                    globalBest.Complemented,
                                    globalBest.FirstOffset);
                            }

                            MergeLowerIndexedSequence(newContig, globalBest, mergeItem1.Sequence);
                        }

                        if (mergeItem2.IsContig)
                        {
                            if (Trace.Want(Trace.AssemblyDetails))
                            {
                                ApplicationLog.WriteLine(
                                    "item {0} is a contig (offset = {1}",
                                    globalBestLargerIndex,
                                    globalBest.SecondOffset);
                            }

                            MergeHigherIndexedContig(newContig, globalBest, mergeItem2.Contig);
                        }
                        else
                        {
                            if (Trace.Want(Trace.AssemblyDetails))
                            {
                                ApplicationLog.WriteLine(
                                    "item {0} is a sequence (offset = {1}",
                                    globalBestLargerIndex,
                                    globalBest.SecondOffset);
                            }

                            MergeHigherIndexedSequence(newContig, globalBest, mergeItem2.Sequence);
                        }

                        MakeConsensus(newContig);
                        if (Trace.Want(Trace.AssemblyDetails))
                        {
                            Dump(newContig);
                        }

                        // Set ConsumedBy value for these poolItems and 
                        // free memory as these sequences are no longer used
                        mergeItem1.ConsumedBy = pool.Count;
                        mergeItem2.ConsumedBy = pool.Count;
                        mergeItem1.FreeSequences();
                        mergeItem2.FreeSequences();

                        pool.Add(new PoolItem(newContig));
                        unconsumedCount--;
                    }
                    else
                    {
                        // None of the alignment scores cross threshold
                        // No more merges possible. So end iteration.
                        break;
                    }
                }
            }

            // no further qualifying merges, so we're done.
            // populate contigs and unmergedSequences
            OverlapDeNovoAssembly sequenceAssembly = new OverlapDeNovoAssembly();
            foreach (PoolItem curItem in pool)
            {
                if (curItem.ConsumedBy < 0)
                {
                    if (curItem.IsContig)
                    {
                        sequenceAssembly.Contigs.Add(curItem.Contig);
                    }
                    else
                    {
                        sequenceAssembly.UnmergedSequences.Add(curItem.Sequence);
                    }
                }
            }

            return sequenceAssembly;
        }
 public void ScoreAvailable(ItemScore itemScore, ResponseInfo responseInfo)
 {
     throw new NotImplementedException();
 }
Esempio n. 27
0
        /// <summary>
        /// Alignes the two input sequence
        /// Updates best score, if necessary
        /// </summary>
        /// <param name="sequence1">First Sequence to be aligned</param>
        /// <param name="sequence2">Second Sequence to be aligned</param>
        /// <param name="reversed">Is first sequence reversed?</param>
        /// <param name="complement">Is first sequence complemented?</param>
        /// <param name="bestScore">Structure to track best score</param>
        /// <param name="sequence1PoolIndex">Index of first sequence in pool.
        /// Used in printing for debug purpose.</param>
        /// <param name="sequence2PoolIndex">Index of second sequence in pool.
        /// Used in printing for debug purpose.</param>
        /// <param name="message">Message to be printed for debug purpose</param>
        /// <returns>Updated best score</returns>
        private ItemScore AlignAndUpdateBestScore(
            ISequence sequence1,
            ISequence sequence2,
            bool reversed,
            bool complement,
            ItemScore bestScore,
            int sequence1PoolIndex,
            int sequence2PoolIndex,
            string message)
        {
            // we will look for the best (largest) overlap score. Note that
            // lower-index items are already in place, so can do this in same pass
            IList <ISequenceAlignment> alignment = RunAlignSimple(sequence1, sequence2);

            if (Trace.Want(Trace.AssemblyDetails))
            {
                ApplicationLog.WriteLine("{0} {1} and {2}", message, sequence1PoolIndex, sequence2PoolIndex);
                Dump(alignment);
            }

            if (alignment.Count > 0 &&
                alignment[0].AlignedSequences.Count > 0)
            {
                long score = 0;
                try
                {
                    score = (long)alignment[0].AlignedSequences[0].Metadata["Score"];
                }
                catch
                {
                    // no impl.
                }

                if (score > bestScore.OverlapScore)
                {
                    bestScore.OverlapScore = score;
                    bestScore.Reversed     = reversed;
                    bestScore.Complemented = complement;
                    long offsets = 0;
                    try
                    {
                        offsets = (long)alignment[0].AlignedSequences[0].Metadata["FirstOffset"];
                    }
                    catch
                    {
                        // no impl.
                    }

                    bestScore.FirstOffset = offsets;
                    offsets = 0;
                    try
                    {
                        offsets = (long)alignment[0].AlignedSequences[0].Metadata["SecondOffset"];
                    }
                    catch
                    {
                        // no impl.
                    }

                    bestScore.SecondOffset = offsets;
                }
            }

            return(bestScore);
        }
        public List <Model.Usluga> RecommendedUsluge(int PacijentId)
        {
            var pacijentoviTermini = _context.Termins.Where(x => x.PacijentId == PacijentId)
                                     .Include(x => x.Pacijent)
                                     .ThenInclude(x => x.Korisnici)
                                     .ThenInclude(x => x.Grad)
                                     .ThenInclude(x => x.Drzava)
                                     .Include(x => x.Usluga).ToList();
            var pacijentoveOcjene = _context.Ocjenes.Where(x => x.PacijentId == PacijentId)
                                    .Include(x => x.Usluga)
                                    .Include(x => x.Pacijent)
                                    .ThenInclude(x => x.Korisnici)
                                    .ThenInclude(x => x.Grad)
                                    .ThenInclude(x => x.Drzava).ToList();
            var pacijentovePretplate = _context.Pretplatas.Where(x => x.PacijentId == PacijentId)
                                       .Include(x => x.Usluga)
                                       .Include(x => x.Pacijent)
                                       .ThenInclude(x => x.Korisnici)
                                       .ThenInclude(x => x.Grad)
                                       .ThenInclude(x => x.Drzava).ToList();


            var userUsluge = new List <Usluga>();

            foreach (var item in pacijentoviTermini)
            {
                var obj = _mapper.Map <Usluga>(item.Usluga);
                if (userUsluge.Find(x => x.UslugaId == obj.UslugaId) == null)
                {
                    userUsluge.Add(obj);
                }
            }
            foreach (var item in pacijentoveOcjene)
            {
                var obj = _mapper.Map <Usluga>(item.Usluga);
                if (userUsluge.Find(x => x.UslugaId == obj.UslugaId) == null)
                {
                    userUsluge.Add(obj);
                }
            }
            foreach (var item in pacijentovePretplate)
            {
                var obj = _mapper.Map <Usluga>(item.Usluga);
                if (userUsluge.Find(x => x.UslugaId == obj.UslugaId) == null)
                {
                    userUsluge.Add(obj);
                }
            }

            var allEvents = _mapper.Map <List <Usluga> >((_context.Uslugas.ToList()));

            foreach (var item in userUsluge)
            {
                if (pacijentoviTermini.Find(x => x.UslugaId == item.UslugaId) != null)
                {
                    allEvents.RemoveAll(x => x.UslugaId == item.UslugaId);
                }
            }

            var eventsWithScore = new List <ItemScore <Usluga> >();

            foreach (var item in allEvents)
            {
                var newItem = new ItemScore <Usluga>
                {
                    Item  = item,
                    Score = 0
                };
                eventsWithScore.Add(newItem);
            }

            foreach (var item in eventsWithScore)
            {
                foreach (var userItem in userUsluge)
                {
                    item.Score += _cbf.CalculateSimilarity(_wordGenerator.GenerateWordBag <Usluga>(item.Item),
                                                           _wordGenerator.GenerateWordBag <Usluga>(userItem));
                }
            }

            eventsWithScore.Sort((a, b) => b.Score.CompareTo(a.Score));
            var recommendedEvents = new List <Usluga>();

            foreach (var item in eventsWithScore)
            {
                recommendedEvents.Add(item.Item);
            }

            return(recommendedEvents.Take(5).ToList());
        }