Ejemplo n.º 1
0
        public void TestInitialize()
        {
            _scorer     = Substitute.For <IScorer>();
            _recogniser = new Recogniser <int>(42, _scorer);

            var img = new Bitmap(TuningParams.ImageSize, TuningParams.ImageSize);
        }
Ejemplo n.º 2
0
 public ComponentManager(IScorer scorer)
 {
     this.scorer = scorer;
     state       = new ComponentManagerState
     {
     };
 }
Ejemplo n.º 3
0
        protected double GetFragmentScore(int seqIndex, int modIndex, IScorer scorer, double?[][] nodeScore, double?[][] maxScore)
        {
            var score = maxScore[seqIndex][modIndex];

            if (score != null)
            {
                return((double)score);
            }

            var node         = _graph[seqIndex][modIndex];
            var curNodeScore = nodeScore[seqIndex][modIndex] ??
                               (nodeScore[seqIndex][modIndex] = scorer.GetFragmentScore(GetComplementaryComposition(seqIndex, modIndex), GetComposition(seqIndex, modIndex)));

            var prevNodeScore = 0.0;

            if (node.GetPrevNodeIndices().Any())
            {
                prevNodeScore =
                    node.GetPrevNodeIndices()
                    .Max(prevNodeIndex => GetFragmentScore(seqIndex - 1, prevNodeIndex, scorer, nodeScore, maxScore));
            }
            maxScore[seqIndex][modIndex] = curNodeScore + prevNodeScore;
            // ReSharper disable PossibleInvalidOperationException
            return((double)maxScore[seqIndex][modIndex]);
            // ReSharper restore PossibleInvalidOperationException
        }
Ejemplo n.º 4
0
        private void Initialize()
        {
            if (_isInitialized)
            {
                return;
            }

            ReloadSettings();
            var gazePointDataProvider = TobiiHost.GetInstance().GetGazePointDataProvider();

            gazePointDataProvider.Start(_identifier.GetInstanceID());

            if (Scorer == null)
            {
                //Scorer = new SingleRayCastNoScore();
                Scorer = new SingleRaycastHistoricHitScore();
                //Scorer = new MultiRaycastHistoricHitScore();
            }
            if (_multiScorer == null)
            {
                _multiScorer = new MultiRaycastHistoricHitScore();
            }

            _isInitialized = true;
        }
Ejemplo n.º 5
0
 public OnlineServer(IScorer scorer,
                     ILog log,
                     string mapName)
 {
     this.scorer  = scorer;
     this.mapName = mapName;
     this.log     = log.Log;
 }
Ejemplo n.º 6
0
 public GreedyEdgeChooserPunterWithStupidZergRush(
     IScorer scorer,
     IGraphVisitor graphVisitor
     )
 {
     this.scorer       = scorer;
     this.graphVisitor = graphVisitor;
 }
Ejemplo n.º 7
0
 public Component(Node node, Node[] mines, IScorer scorer)
 {
     Id    = Guid.NewGuid();
     Nodes = new List <Node> {
         node
     };
     Score = new ComponentScore(node, mines, scorer);
 }
Ejemplo n.º 8
0
 internal void Initialize(IndexNode node, IIndexNavigatorPool pool, IScorer scorer)
 {
     this.pool                  = pool;
     this.scorer                = scorer;
     this.currentNode           = node;
     this.intraNodeTextPosition = 0;
     this.navigatedWith.Length  = 0;
 }
 public GreedyEdgeChooserPunter(
     IScorer scorer,
     IGraphVisitor graphVisitor
     )
 {
     this.scorer       = scorer;
     this.graphVisitor = graphVisitor;
 }
 public BargeHauler3(
     IScorer scorer,
     IGraphVisitor graphVisitor
     )
 {
     this.scorer       = scorer;
     this.graphVisitor = graphVisitor;
 }
Ejemplo n.º 11
0
 public Game(IEnumerable <IPlayer> players, IScorer scorer, uint rounds)
 {
     _Players = players;
     _Scorer  = scorer;
     // Initialise the players
     _Scorer.Start(_Players);
     _Rounds = rounds;
     _Round  = 0;
 }
 public FriendshipPunter(IScorer scorer)
 {
     this.scorer      = scorer;
     graphVisitor     = new GraphVisitor();
     componentManager = new ComponentManager(scorer);
     state            = new PunterState
     {
     };
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Prevents a default instance of the <see cref="Engine" /> class from being created.
 /// </summary>
 private Engine()
 {
     this.consoleDrawer = new ConsoleRenderer();
     this.consoleReader = new ConsoleInput();
     this.inputHandler  = new InputHandler(this.consoleDrawer, this.consoleReader);
     this.mineFactory   = new MineCreator();
     this.highscore     = new HighScore();
     this.finalScore    = InitialScore;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Get the fragment score at the provided sequence index and mod index, using the provided scorer
        /// </summary>
        /// <param name="seqIndex"></param>
        /// <param name="modIndex"></param>
        /// <param name="scorer"></param>
        /// <param name="nodeScore"></param>
        /// <param name="maxScore"></param>
        /// <returns></returns>
        protected double GetFragmentScore(int seqIndex, int modIndex, IScorer scorer, double?[][] nodeScore, double?[][] maxScore)
        {
            var score = maxScore[seqIndex][modIndex];

            if (score != null)
            {
                return((double)score);
            }

            var    node = _graph[seqIndex][modIndex];
            double?curNodeScore;

            if (nodeScore[seqIndex][modIndex] != null)
            {
                curNodeScore = nodeScore[seqIndex][modIndex];
            }
            else
            {
                var prefixFragmentComposition = GetComplementaryComposition(seqIndex, modIndex);
                var suffixFragmentComposition = GetComposition(seqIndex, modIndex);

                if (scorer == null)
                {
                    Console.WriteLine("Null scorer");
                    curNodeScore = 0;
                }
                else
                {
                    nodeScore[seqIndex][modIndex] = scorer.GetFragmentScore(prefixFragmentComposition,
                                                                            suffixFragmentComposition);
                    curNodeScore = nodeScore[seqIndex][modIndex];
                }
            }

            var prevNodeScore = 0.0;

            if (node.GetPrevNodeIndices().Any())
            {
                foreach (var previousNode in node.GetPrevNodeIndices())
                {
                    if (seqIndex == 0)
                    {
                        continue;
                    }

                    var prevScore = GetFragmentScore(seqIndex - 1, previousNode, scorer, nodeScore, maxScore);
                    if (prevScore > prevNodeScore)
                    {
                        prevNodeScore = prevScore;
                    }
                }
            }
            maxScore[seqIndex][modIndex] = curNodeScore + prevNodeScore;
            // ReSharper disable PossibleInvalidOperationException
            return((double)maxScore[seqIndex][modIndex]);
            // ReSharper restore PossibleInvalidOperationException
        }
Ejemplo n.º 15
0
 public BetStrategyService(IGameRepository gameRepository, IBetRepository betRepository, IStrategyRepository strategyRepository,
                           IStrategyFactory strategyFactory, IRankingRepository rankingRepository, IScorer scorer)
 {
     this._gameRepository     = gameRepository;
     this._betRepository      = betRepository;
     this._strategyRepository = strategyRepository;
     this._strategyFactory    = strategyFactory;
     this._rankingRepository  = rankingRepository;
     this._scorer             = scorer;
 }
Ejemplo n.º 16
0
 public BetStrategyService(IGameRepository gameRepository, IBetRepository betRepository, IStrategyRepository strategyRepository, 
     IStrategyFactory strategyFactory,IRankingRepository rankingRepository, IScorer scorer)
 {
     this._gameRepository = gameRepository;
     this._betRepository = betRepository;
     this._strategyRepository = strategyRepository;
     this._strategyFactory = strategyFactory;
     this._rankingRepository = rankingRepository;
     this._scorer = scorer;
 }
Ejemplo n.º 17
0
 public Level(IScorer score, int winScore)
 {
     score.Updated += (sender, args) =>
     {
         if (args.Score >= winScore)
         {
             OnWon(new WonArgs());
         }
     };
 }
Ejemplo n.º 18
0
 public void OneTimeSetUp()
 {
     _Scorer = new SimpleScorer();
     // No need to set a strategy
     _Players = new SimplePlayer[] {
         new SimplePlayer(@"Player 1", new RandomStrategy(null)),
         new SimplePlayer(@"Player 2", new RandomStrategy(null)),
         new SimplePlayer(@"Player 3", new RandomStrategy(null))
     };
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CitySearchEngine" /> class
 /// </summary>
 /// <param name="searchDataRepository">The search data repository</param>
 /// <param name="indexedSearchDataRepository">The indexed data repository</param>
 /// <param name="queryScorer">The query scorer</param>
 /// <param name="locationScorer">The location scorer</param>
 public CitySearchEngine(
     ISearchDataRepository searchDataRepository,
     IIndexedSearchDataRepository indexedSearchDataRepository,
     IScorer <string> queryScorer,
     IScorer <LocationInformation> locationScorer)
 {
     this.searchDataRepository        = searchDataRepository;
     this.indexedSearchDataRepository = indexedSearchDataRepository;
     this.queryScorer    = queryScorer;
     this.locationScorer = locationScorer;
 }
Ejemplo n.º 20
0
        public GameService(IGameRepository gameRepository, IBetRepository betRepository, IRankingRepository rankingRepository, IScorer scorer)
        {
            if (gameRepository == null) throw new ArgumentNullException("gameRepository");
            if (betRepository == null) throw new ArgumentNullException("betRepository");
            if (scorer == null) throw new ArgumentNullException("scorer");

            this._gameRepository = gameRepository;
            this._betRepository = betRepository;
            this._rankingRepository = rankingRepository;
            this._scorer = scorer;
        }
 public ComponentScore(Node node, Node[] mines, IScorer scorer)
 {
     Mines  = new[] { node }.Where(x => x.IsMine).ToList();
     Scores = new Dictionary <int, long>();
     foreach (var mine in mines)
     {
         var d = scorer.GetDistance(mine, node);
         Scores.Add(mine.Id, d * d);
     }
     SelfScore = Mines.Sum(x => Scores[x.Id]);
 }
Ejemplo n.º 22
0
 public Component(Node node, Node[] mines, IScorer scorer)
 {
     Nodes = new List <Node> {
         node
     };
     Mines = Nodes.Where(x => x.IsMine).ToList();
     foreach (var mine in mines)
     {
         var d = scorer.GetDistance(mine, node);
         Scores.Add(mine.Id, d * d);
     }
 }
Ejemplo n.º 23
0
        public void OneTimeSetUp()
        {
            _Scorer = new SimpleScorer();

            var rockPlayer     = new SimplePlayer(@"Rock Player", new MockStrategy(HandGesture.Rock));
            var paperPlayer    = new SimplePlayer(@"Rock Player", new MockStrategy(HandGesture.Paper));
            var scissorsPlayer = new SimplePlayer(@"Rock Player", new MockStrategy(HandGesture.Scissors));

            _NoPlayers    = new IPlayer[] {};
            _OnePlayer    = new IPlayer[] { rockPlayer };
            _TwoPlayers   = new IPlayer[] { rockPlayer, paperPlayer };
            _ThreePlayers = new IPlayer[] { rockPlayer, paperPlayer, scissorsPlayer };
        }
Ejemplo n.º 24
0
        /// <param name="symbol">The symbol which the given scorer is optimised for</param>
        /// <param name="scorer">An object which is trained to recognise the symbol specified by the <c>symbol</c> param</param>
        public Recogniser(TSymbol symbol, IScorer scorer)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException(nameof(symbol));
            }
            if (scorer == null)
            {
                throw new ArgumentNullException(nameof(scorer));
            }

            this.Symbol = symbol;
            _scorer     = scorer;
        }
Ejemplo n.º 25
0
 public AbPruningAi(PieceType player,
                    int maxDepth,
                    IScorer scorer,
                    IMoveEnumerator moveEnumerator,
                    IBoardFactory boardFactory,
                    IJudge judge)
 {
     this.player         = player;
     this.maxDepth       = maxDepth;
     this.scorer         = scorer;
     this.moveEnumerator = moveEnumerator;
     this.boardFactory   = boardFactory;
     this.judge          = judge;
 }
Ejemplo n.º 26
0
        /// <summary>
        /// Get the fragment score at the provided sequence index and mod index, using the provided scorer
        /// </summary>
        /// <param name="seqIndex"></param>
        /// <param name="modIndex"></param>
        /// <param name="scorer"></param>
        /// <param name="nodeScore"></param>
        /// <param name="maxScore"></param>
        /// <returns></returns>
        protected double GetFragmentScore(int seqIndex, int modIndex, IScorer scorer, double?[][] nodeScore, double?[][] maxScore)
        {
            var score = maxScore[seqIndex][modIndex];

            if (score != null)
            {
                return((double)score);
            }

            var node = _graph[seqIndex][modIndex];

            /*double? curNodeScore;
             *
             * if (nodeScore[seqIndex][modIndex] != null)
             * {
             *  curNodeScore = nodeScore[seqIndex][modIndex];
             * }
             * else
             * {
             *  var prefixFragmentComposition = GetComplementaryComposition(seqIndex, modIndex);
             *  var suffixFragmentComposition = GetComposition(seqIndex, modIndex);
             *
             *  if (scorer == null)
             *  {
             *      ConsoleMsgUtils.ShowWarning("Null scorer in GetFragmentScore");
             *      curNodeScore = 0;
             *  }
             *  else
             *  {
             *      nodeScore[seqIndex][modIndex] = scorer.GetFragmentScore(prefixFragmentComposition,
             *                                                              suffixFragmentComposition);
             *      curNodeScore = nodeScore[seqIndex][modIndex];
             *  }
             * }*/
            var curNodeScore = nodeScore[seqIndex][modIndex] ??
                               (nodeScore[seqIndex][modIndex] = scorer.GetFragmentScore(GetComplementaryComposition(seqIndex, modIndex), GetComposition(seqIndex, modIndex)));

            var prevNodeScore = 0.0;

            if (node.GetPrevNodeIndices().Any() && seqIndex > 0)
            {
                prevNodeScore = node.GetPrevNodeIndices().Max(previousNode => GetFragmentScore(seqIndex - 1, previousNode, scorer, nodeScore, maxScore));
            }
            maxScore[seqIndex][modIndex] = curNodeScore + prevNodeScore;
            // ReSharper disable PossibleInvalidOperationException
            return((double)maxScore[seqIndex][modIndex]);
            // ReSharper restore PossibleInvalidOperationException
        }
Ejemplo n.º 27
0
        public void WonPoint(string playerName)
        {
            if (playerName == scorer.PlayerOneName)
            {
                scorer = scorer.PlayerOneWin();
                return;
            }

            if (playerName == scorer.PlayerTwoName)
            {
                scorer = scorer.PlayerTwoWin();
                return;
            }

            throw new InvalidOperationException($"Unknown player name: {playerName}");
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Get the score for a protein or peptide sequence.
        /// </summary>
        /// <param name="scorer">The scorer.</param>
        /// <param name="sequence">The sequence.</param>
        /// <returns>The score calculated from the sequence.</returns>
        public static double ScoreSequence(IScorer scorer, Sequence sequence)
        {
            var prefixCompositions = GetCompositions(sequence, true);
            var suffixCompositions = GetCompositions(sequence, false);

            suffixCompositions.Reverse();

            var score = 0.0;

            for (var i = 0; i < prefixCompositions.Count; i++)
            {
                score += scorer.GetFragmentScore(prefixCompositions[i], suffixCompositions[i]);
            }

            return(score);
        }
Ejemplo n.º 29
0
        public CardGame(CardGameCommands commands, IPlayerCollection players, IDeck deck, IScorer scorer, IVictoryChecker victoryChecker)
        {
            Guard.AgainstNullDataContainer(commands, nameof(commands));
            Guard.AgainstNull(players, nameof(players));
            Guard.AgainstNull(deck, nameof(deck));
            Guard.AgainstNull(scorer, nameof(scorer));
            Guard.AgainstNull(victoryChecker, nameof(victoryChecker));

            this.drawCardsCommandHandler = commands.DrawCardsCommandHandler;
            this.updateScoresCommand     = commands.UpdateScoresCommandHandler;
            this.handleGameEndCommand    = commands.CheckForGameEndCommandHandler;
            this.players        = players;
            this.deck           = deck;
            this.scorer         = scorer;
            this.victoryChecker = victoryChecker;
        }
Ejemplo n.º 30
0
        public IcScores GetIcScores(IInformedScorer informedScorer, IScorer scorer, string seqStr, Composition composition)
        {
            var seqGraph = SequenceGraph.CreateGraph(AminoAcidSet, AminoAcid.ProteinNTerm, seqStr, AminoAcid.ProteinCTerm);

            if (seqGraph == null)
            {
                return(null);
            }

            var bestScore = double.NegativeInfinity;
            Tuple <double, string> bestScoreAndModifications = null;
            var protCompositions = seqGraph.GetSequenceCompositions();

            for (var modIndex = 0; modIndex < protCompositions.Length; modIndex++)
            {
                seqGraph.SetSink(modIndex);
                var protCompositionWithH2O = seqGraph.GetSinkSequenceCompositionWithH2O();

                if (!protCompositionWithH2O.Equals(composition))
                {
                    continue;
                }

                var curScoreAndModifications = seqGraph.GetFragmentScoreAndModifications(scorer);
                var curScore = curScoreAndModifications.Item1;

                if (!(curScore > bestScore))
                {
                    continue;
                }

                bestScoreAndModifications = curScoreAndModifications;
                bestScore = curScore;
            }

            if (bestScoreAndModifications == null)
            {
                return(null);
            }

            var modifications       = bestScoreAndModifications.Item2;
            var sequence            = Sequence.CreateSequence(seqStr, modifications, this.AminoAcidSet);
            var numMatchedFragments = informedScorer.GetNumMatchedFragments(sequence);
            var score = informedScorer.GetUserVisibleScore(sequence);

            return(new IcScores(numMatchedFragments, score, modifications));
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Get the fragment score and string-format modifications of this sequence graph
        /// </summary>
        /// <param name="scorer"></param>
        /// <returns></returns>
        public Tuple <double, string> GetFragmentScoreAndModifications(IScorer scorer)
        {
            var nodeScore = new double?[_maxSeqIndex][];
            var maxScore  = new Tuple <double, string> [_maxSeqIndex][];

            for (var si = 0; si < _maxSeqIndex; si++)
            {
                nodeScore[si] = new double?[_graph[si].Length];
                maxScore[si]  = new Tuple <double, string> [_graph[si].Length];
            }
            maxScore[0][0] = new Tuple <double, string>(0.0, "");
            nodeScore[_index][_sinkModIndex] = 0.0;

            var fragmentScore = GetFragmentScoreAndModifications(_index, _sinkModIndex, scorer, nodeScore, maxScore);

            return(new Tuple <double, string>(fragmentScore.Item1, fragmentScore.Item2));
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Get the fragment score using the provided scorer
        /// </summary>
        /// <param name="scorer"></param>
        /// <returns></returns>
        public double GetFragmentScore(IScorer scorer)
        {
            var nodeScore = new double?[_maxSeqIndex][];
            var maxScore  = new double?[_maxSeqIndex][];

            for (var si = 0; si < _maxSeqIndex; si++)
            {
                nodeScore[si] = new double?[_graph[si].Length];
                maxScore[si]  = new double?[_graph[si].Length];
            }
            maxScore[0][0] = 0.0;
            nodeScore[_index][_sinkModIndex] = 0.0;

            var fragmentScore = GetFragmentScore(_index, _sinkModIndex, scorer, nodeScore, maxScore);

            return(fragmentScore);
        }
Ejemplo n.º 33
0
 public TagMatchFinder(
     ProductSpectrum spec,
     IScorer ms2Scorer,
     LcMsPeakMatrix featureFinder,
     string proteinSequence, 
     Tolerance tolerance, 
     AminoAcidSet aaSet, 
     double maxSequenceMass)
 {
     _spec = spec;
     _ms2Scorer = ms2Scorer;
     _featureFinder = featureFinder;
     _proteinSequence = proteinSequence;
     _tolerance = tolerance;
     _aaSet = aaSet;
     _maxSequenceMass = maxSequenceMass;
 }
Ejemplo n.º 34
0
        private Tuple<double, string> GetFragmentScoreAndModifications(int seqIndex, int modIndex, IScorer scorer, double?[][] nodeScore, Tuple<double, string>[][] maxScoreAndMods)
        {
            var scoreAndMods = maxScoreAndMods[seqIndex][modIndex];
            if (scoreAndMods != null) return scoreAndMods;

            var node = _graph[seqIndex][modIndex];
            var curNodeScore = nodeScore[seqIndex][modIndex] ??
                (nodeScore[seqIndex][modIndex] = scorer.GetFragmentScore(GetComplementaryComposition(seqIndex, modIndex), GetComposition(seqIndex, modIndex)));

            var bestPrevNodeIndex = -1;
            var bestPrevNodeScore = double.NegativeInfinity;
            string bestPrevSequence = null;
            foreach (var prevNodeIndex in node.GetPrevNodeIndices())
            {
                var prevNodeScoreAndSequence = GetFragmentScoreAndModifications(seqIndex - 1, prevNodeIndex, scorer,
                    nodeScore, maxScoreAndMods);
                var prevNodeScore = prevNodeScoreAndSequence.Item1;
                if (prevNodeScore > bestPrevNodeScore)
                {
                    bestPrevNodeIndex = prevNodeIndex;
                    bestPrevNodeScore = prevNodeScore;
                    bestPrevSequence = prevNodeScoreAndSequence.Item2;
                }
            }

            if (bestPrevNodeIndex < 0)  // source
            {
                return maxScoreAndMods[seqIndex][modIndex] = new Tuple<double, string>((double)curNodeScore, "");
            }

            var modPos = _index - seqIndex;
            var aminoAcid = _aminoAcidSequence[seqIndex];
            var modAa = aminoAcid as ModifiedAminoAcid;
            if (modAa != null)
            {
                var modificationName = modAa.Modification.Name;
                if (string.IsNullOrEmpty(bestPrevSequence))
                {
                    bestPrevSequence = modificationName + " " + modPos;
                }
                else
                {
                    bestPrevSequence = modificationName + " " + modPos + "," + bestPrevSequence;
                }
            }

            var prevModCombIndex = _graph[seqIndex - 1][bestPrevNodeIndex].ModificationCombinationIndex;
            var curModCombIndex = node.ModificationCombinationIndex;
            if (prevModCombIndex != curModCombIndex) // modified
            {
                var modificationName = ModificationParams.GetModificationIndexBetween(prevModCombIndex, curModCombIndex).Name;
                string newModSequence;
                if (string.IsNullOrEmpty(bestPrevSequence))
                {
                    newModSequence = modificationName + " " + modPos;
                }
                else
                {
                    newModSequence = modificationName + " " + modPos + ",";
                }
                return maxScoreAndMods[seqIndex][modIndex] = new Tuple<double, string>
                    ((double)curNodeScore + bestPrevNodeScore, newModSequence+bestPrevSequence);
            }

            return maxScoreAndMods[seqIndex][modIndex] = new Tuple<double, string>
                ((double)curNodeScore + bestPrevNodeScore, bestPrevSequence);
        }
Ejemplo n.º 35
0
 public ScoreService(IRepository repository)
 {
     _repository = repository;
     _scorer = new Scorer();
 }
Ejemplo n.º 36
0
        void OnScorerScoreChanged(IScorer scorer, float score)
        {
            l.Trace(scorer.ToString() + " score: " + score);

            // if before min change mind time, queue an update for when that time comes

            // OPTIMIZE - could cache the current highest score and scorer to see if the highest one dipped (in which case, recalculate highest from all), or if a non-highest one beat the current high score

            SelectedChild = GetHighestScore();
        }
Ejemplo n.º 37
0
        private IEnumerable<TagSequenceMatch> GetMatches(IEnumerable<SequenceTag> tags, ProductSpectrum spec, IScorer scorer)
        {
            // Match tags against the database
            var proteinsToTags = GetProteinToMatchedTagsMap(tags, _searchableDb, _aaSet, _tolerance, _tolerance);
            //var tagSequenceMatchList = new List<TagSequenceMatch>();

            // Extend matches
            foreach (var entry in proteinsToTags)
            {
                var proteinName = entry.Key;
                var matchedTagSet = entry.Value;
                var proteinSequence = matchedTagSet.Sequence;

                var tagFinder = new TagMatchFinder(spec, scorer, _featureFinder, proteinSequence, _tolerance, _aaSet, _maxSequenceMass);

                foreach (var matchedTag in matchedTagSet.Tags)
                {
                    if (matchedTag.Length < _minMatchedTagLength) continue;
                    if (matchedTag.NTermFlankingMass == null && matchedTag.CTermFlankingMass == null) continue;

                    var matches = tagFinder.FindMatches(matchedTag).ToArray();
                    //var prevScore = double.NegativeInfinity;
                    //foreach (var match in matches.OrderByDescending(m => m.Score))
                    foreach(var match in matches)
                    {
                        var sequence = proteinSequence.Substring(match.StartIndex, match.EndIndex - match.StartIndex);
                        //re-scoring
                        var sequenceObj = Sequence.CreateSequence(sequence, match.ModificationText, _aaSet);
                        match.Score = sequenceObj.GetInternalCleavages().Sum(c => scorer.GetFragmentScore(c.PrefixComposition, c.SuffixComposition));

                        //var numMatches = matchedTag.Length * 2 + match.NTermScore + match.CTermScore;
                        //var score = match.NTermScore + match.CTermScore;
                        //score += (matchedTag.NumReliableNTermFlankingMasses > 0)
                          //  ? matchedTag.Length*CompositeScorer.ScoreParam.Prefix.ConsecutiveMatch
                            //: matchedTag.Length*CompositeScorer.ScoreParam.Suffix.ConsecutiveMatch;
                        

                        // Poisson p-value score
                        //var n = (match.EndIndex - match.StartIndex - 1)*2;
                        //var lambda = numMatches / n;
                        //var pValue = 1 - Poisson.CDF(lambda, numMatches);
                        //var pScore = (pValue > 0) ? - Math.Log(pValue, 2) : 50.0;
                        //if (numMatches < 5) break;
                        //if (prevScore - numMatches > 2) break;
                        //prevScore = numMatches;

                        var pre = match.StartIndex == 0 ? '-' : proteinSequence[match.StartIndex - 1]; // startIndex is inclusive
                        var post = match.EndIndex >= proteinSequence.Length ? '-' : proteinSequence[match.EndIndex]; // endIndex is Exclusive

                        yield return new TagSequenceMatch(sequence, proteinName, match, pre, post);

                        //tagSequenceMatchList.Add(new TagSequenceMatch(sequence, proteinName, match, pre, post));
                    }
                }
            }
            //return tagSequenceMatchList;
        }
Ejemplo n.º 38
0
        protected double GetFragmentScore(int seqIndex, int modIndex, IScorer scorer, double?[][] nodeScore, double?[][] maxScore)
        {
            var score = maxScore[seqIndex][modIndex];
            if (score != null) return (double)score;

            var node = _graph[seqIndex][modIndex];
            var curNodeScore = nodeScore[seqIndex][modIndex] ??
                (nodeScore[seqIndex][modIndex] = 
                    _isForward ? scorer.GetFragmentScore(GetComposition(seqIndex, modIndex), GetComplementaryComposition(seqIndex, modIndex))
                    : scorer.GetFragmentScore(GetComplementaryComposition(seqIndex, modIndex), GetComposition(seqIndex, modIndex))
                    );

            var prevNodeScore = 0.0;
            if (node.GetPrevNodeIndices().Any())
            {
                prevNodeScore =
                    node.GetPrevNodeIndices()
                        .Max(prevNodeIndex => GetFragmentScore(seqIndex - 1, prevNodeIndex, scorer, nodeScore, maxScore));
            }
            maxScore[seqIndex][modIndex] = curNodeScore + prevNodeScore;
            // ReSharper disable PossibleInvalidOperationException
            return (double)maxScore[seqIndex][modIndex];
            // ReSharper restore PossibleInvalidOperationException
        }
Ejemplo n.º 39
0
        private Tuple<double, LinkedList<ModificationInstance>> GetFragmentScoreAndModifications(int seqIndex, int modIndex,
            IScorer scorer, double?[][] nodeScore, Tuple<double, LinkedList<ModificationInstance>>[][] maxScoreAndMods)
        {
            var scoreAndMods = maxScoreAndMods[seqIndex][modIndex];
            if (scoreAndMods != null) return scoreAndMods;

            var node = _graph[seqIndex][modIndex];
            var curNodeScore = nodeScore[seqIndex][modIndex] ??
                               (nodeScore[seqIndex][modIndex] = _isForward
                                   ? scorer.GetFragmentScore(GetComposition(seqIndex, modIndex),
                                       GetComplementaryComposition(seqIndex, modIndex))
                                   : scorer.GetFragmentScore(GetComplementaryComposition(seqIndex, modIndex),
                                       GetComposition(seqIndex, modIndex))
                                   );

            var bestPrevNodeIndex = -1;
            var bestPrevNodeScore = double.NegativeInfinity;
            LinkedList<ModificationInstance> bestPrevMods = null;
            foreach (var prevNodeIndex in node.GetPrevNodeIndices())
            {
                var prevNodeScoreAndSequence = GetFragmentScoreAndModifications(seqIndex - 1, prevNodeIndex, scorer,
                    nodeScore, maxScoreAndMods);
                var prevNodeScore = prevNodeScoreAndSequence.Item1;
                if (prevNodeScore > bestPrevNodeScore)
                {
                    bestPrevNodeIndex = prevNodeIndex;
                    bestPrevNodeScore = prevNodeScore;
                    bestPrevMods = prevNodeScoreAndSequence.Item2;
                }
            }

            if (bestPrevNodeIndex < 0)  // source
            {
                return maxScoreAndMods[seqIndex][modIndex] = new Tuple<double, LinkedList<ModificationInstance>>((double)curNodeScore, new LinkedList<ModificationInstance>());
            }

            var modPos = _isForward ? seqIndex : _index - seqIndex;
            if (modPos <= 1) --modPos;
            var aminoAcid = _aminoAcidSequence[seqIndex];
            var modAa = aminoAcid as ModifiedAminoAcid;

            LinkedList<ModificationInstance> newMods = null;
            if (modAa != null)
            {
                newMods = bestPrevMods == null ? new LinkedList<ModificationInstance>() : new LinkedList<ModificationInstance>(bestPrevMods);
                var modIns = new ModificationInstance(modAa.Modification, modPos);
                if (_isForward) newMods.AddLast(modIns);
                else newMods.AddFirst(modIns);
            }

            var prevModCombIndex = _graph[seqIndex - 1][bestPrevNodeIndex].ModificationCombinationIndex;
            var curModCombIndex = node.ModificationCombinationIndex;
            if (prevModCombIndex != curModCombIndex) // modified
            {
                if (newMods == null)
                {
                    newMods = bestPrevMods == null ? new LinkedList<ModificationInstance>() : new LinkedList<ModificationInstance>(bestPrevMods);
                }
                var modification = ModificationParams.GetModificationIndexBetween(prevModCombIndex, curModCombIndex);
                var modIns = new ModificationInstance(modification, modPos);
                if (_isForward) newMods.AddLast(modIns);
                else newMods.AddFirst(modIns);
            }

            return maxScoreAndMods[seqIndex][modIndex] = new Tuple<double, LinkedList<ModificationInstance>>
                ((double)curNodeScore + bestPrevNodeScore, newMods ?? bestPrevMods);
        }
Ejemplo n.º 40
0
        public Tuple<double, LinkedList<ModificationInstance>> GetScoreAndModifications(IScorer scorer)
        {
            var nodeScore = new double?[_maxSeqIndex][];
            var maxScore = new Tuple<double, LinkedList<ModificationInstance>>[_maxSeqIndex][];
            for (var si = 0; si <= _index; si++)
            {
                nodeScore[si] = new double?[_graph[si].Length];
                maxScore[si] = new Tuple<double, LinkedList<ModificationInstance>>[_graph[si].Length];
            }
            maxScore[0][0] = new Tuple<double, LinkedList<ModificationInstance>>(0.0, new LinkedList<ModificationInstance>());
            nodeScore[_index][_sinkModIndex] = 0.0;

            var fragmentScore = GetFragmentScoreAndModifications(_index, _sinkModIndex, scorer, nodeScore,
                maxScore);

            return new Tuple<double, LinkedList<ModificationInstance>>(fragmentScore.Item1, fragmentScore.Item2);
        }
Ejemplo n.º 41
0
        public double GetFragmentScore(IScorer scorer)
        {
            var nodeScore = new double?[_maxSeqIndex][];
            var maxScore = new double?[_maxSeqIndex][];
            for (var si = 0; si <= _index; si++)
            {
                nodeScore[si] = new double?[_graph[si].Length];
                maxScore[si] = new double?[_graph[si].Length];
            }
            maxScore[0][0] = 0.0;
            nodeScore[_index][_sinkModIndex] = 0.0;

            var fragmentScore = GetFragmentScore(_index, _sinkModIndex, scorer, nodeScore, maxScore);
            return fragmentScore;
        }
Ejemplo n.º 42
0
 public void CreateScorer()
 {
     _scorer = new TenPinScorer();
 }
Ejemplo n.º 43
0
 public RankingRepository(IBetRepository betRepository, IScorer scorer)
 {
     this._betRepository = betRepository;
     this._scorer = scorer;
 }