private void ReportPerHla(OptimizationParameterList qmrrParams, Dictionary <string, BestSoFar <double, TrueCollection> > peptideToBestHlaAssignmentSoFar,
                                  string directory, string name)
        {
            string fileName = string.Format(@"{0}\NoisyOr.PeptideHlaProbability.{1}.new.txt", directory, name);

            using (StreamWriter output = File.CreateText(fileName))
            {
                output.WriteLine(SpecialFunctions.CreateTabString("Peptide", "HLA", "LogOdds", "Probability"));
                foreach (QmrrPartialModel qmrrPartialModel in QmrrPartialModelCollection)
                {
                    QmrrModelMissingAssignment         aQmrrModelMissingAssignment = QmrrModelMissingAssignment.GetInstance(ModelLikelihoodFactories, qmrrPartialModel, qmrrParams);
                    BestSoFar <double, TrueCollection> bestHlaAssignment           = peptideToBestHlaAssignmentSoFar[qmrrPartialModel.Peptide];
                    Set <Hla> trueCollectionFullAsSet = new Set <Hla>(bestHlaAssignment.Champ);

                    double loglikelihoodFull = bestHlaAssignment.ChampsScore;
                    foreach (Hla hla in trueCollectionFullAsSet)
                    {
                        bool known = qmrrPartialModel.KnownHlaSet.Contains(hla);
                        if (!known)
                        {
                            Set <Hla>      allLessOne            = trueCollectionFullAsSet.SubtractElement(hla);
                            TrueCollection trueCollectionWithout = TrueCollection.GetInstance(allLessOne);
                            double         loglikelihoodWithout  = aQmrrModelMissingAssignment.LogLikelihoodOfCompleteModelConditionedOnKnownHlas(trueCollectionWithout);
                            double         logOdds            = loglikelihoodFull - loglikelihoodWithout;
                            double         probabilityFull    = Math.Exp(loglikelihoodFull);
                            double         probabilityWithout = Math.Exp(loglikelihoodWithout);
                            double         probability        = probabilityFull / (probabilityFull + probabilityWithout);
                            Debug.Assert(logOdds >= 0); // real assert
                            output.WriteLine(SpecialFunctions.CreateTabString(qmrrPartialModel.Peptide, hla, logOdds, probability));
                        }
                    }
                }
            }
        }
        public static QmrrModelMissingAssignment GetInstance(ModelLikelihoodFactories modelLikelihoodFactories, QmrrPartialModel qmrrPartialModel, OptimizationParameterList qmrrParams)
        {
            QmrrModelMissingAssignment aQmrrModelMissingAssignment = new QmrrModelMissingAssignment();

            aQmrrModelMissingAssignment.QmrrPartialModel          = qmrrPartialModel;
            aQmrrModelMissingAssignment.OptimizationParameterList = qmrrParams;
            aQmrrModelMissingAssignment.KnownHlaSet = qmrrPartialModel.KnownHlaSet;
            aQmrrModelMissingAssignment.SwitchableHlasOfRespondingPatients = qmrrPartialModel.SwitchableHlasOfRespondingPatients;
            aQmrrModelMissingAssignment.ModelLikelihoodFactories           = modelLikelihoodFactories;
            aQmrrModelMissingAssignment.LogLikelihoodOfCompleteModelConditionedOnKnownHlas = modelLikelihoodFactories.MissingAssignmentDelegateFactory(qmrrPartialModel, qmrrParams);
            return(aQmrrModelMissingAssignment);
            //SetOfAllHlasCount = qmrrPartialModel.HlaList.Count;
        }
Beispiel #3
0
        protected QmmrModelOnePeptide QmmrModelOnePeptideGetInstance(QmrrPartialModel qmrrPartialModel, OptimizationParameterList qmrrParams, double depth)
        {
            QmmrModelOnePeptide aQmmrModelOnePeptide = new QmmrModelOnePeptide();

            aQmmrModelOnePeptide.QmrrModelMissingAssignment = QmrrModelMissingAssignment.GetInstance(ModelLikelihoodFactories, qmrrPartialModel, qmrrParams);
            aQmmrModelOnePeptide.CreateNoSwitchablesHlaAssignment();
            if (depth == 0)
            {
                // do nothing
            }
            else if (depth == Math.Floor(depth))
            {
                SpecialFunctions.CheckCondition(depth > 0);
                aQmmrModelOnePeptide.SetForDepthSearch((int)Math.Floor(depth));
            }
            else
            {
                SpecialFunctions.CheckCondition(depth == 1.5);
                aQmmrModelOnePeptide.SetForBitFlipsAnd1Replacement();
            }
            return(aQmmrModelOnePeptide);
        }