//!!!Yikes tons of repeated code and stuff re-run
        internal static HlaAssignmentWithResponses CreateHlaAssignment(Quickscore <Hla, int> quickscore, string hlaListAsString, ICollection <int> patientsWhoRespond)
        {
            Qmrr.HlaFactory hlaFactory = Qmrr.HlaFactory.GetFactory("noConstraint");

            //!!!this code is repeated elsewhere
            Dictionary <Hla, List <int> > hlaToRespondingPatientsUnfiltered = quickscore.CreateCauseToSubsetOfEffects(patientsWhoRespond);
            Dictionary <Hla, List <int> > hlaToRespondingPatients           = Filter9xs(hlaToRespondingPatientsUnfiltered);
            List <Hla> hlaListFromRepondingPatients = new List <Hla>(hlaToRespondingPatients.Keys);

            Dictionary <Hla, bool> hlaAssignmentDicationary = new Dictionary <Hla, bool>();

            foreach (string hlaName in hlaListAsString.Split(';'))
            {
                Hla hla = hlaFactory.GetGroundInstance(hlaName);
                hlaAssignmentDicationary[hla] = true;
            }

            List <int> indexCollection = new List <int>();

            for (int hlaIndex = 0; hlaIndex < hlaListFromRepondingPatients.Count; ++hlaIndex)
            {
                Hla hla = hlaListFromRepondingPatients[hlaIndex];
                if (hlaAssignmentDicationary.ContainsKey(hla))
                {
                    indexCollection.Add(hlaIndex);
                }
            }

            HlaAssignmentWithResponses hlaAssignment = HlaAssignmentWithResponses.GetInstance(quickscore, hlaListFromRepondingPatients,
                                                                                              indexCollection, hlaToRespondingPatients);

            return(hlaAssignment);
        }
        internal static string GetAminoAcid(int position, bool treatHlaAsPrefix, Hla hla)
        {
            string sequence;

            if (treatHlaAsPrefix)
            {
                sequence = null;
                foreach (string hlaPrefix in EveryPrefixInclusiveDownToTwoDigits(hla.ToString()))
                {
                    if (HlaNameToSequenceAsPrefix.TryGetValue(hlaPrefix, out sequence)) // Will also get a hit because empty string is included.
                    {
                        break;
                    }
                }
                SpecialFunctions.CheckCondition(null != sequence, "The hla, even trimmed two length 3 (class letter and two digits), not found in HlaToSequence file: '" + hla.ToString() + "'.");
            }
            else
            {
                sequence = HlaNameToSequenceExact[hla.ToString()];
            }
            char   aminoAcidChar = sequence[position - 1];
            string sAminoAcid    = VirusCount.Biology.GetInstance().OneLetterAminoAcidAbbrevTo3Letter[aminoAcidChar];

            return(sAminoAcid);
        }
        static public bool?HasHla(Hla hlaGoal, Dictionary <string, string> row, HlaResolution hlaResolution)
        {
            bool hasNull = false;

            for (int i = 1; i <= 2; ++i)
            {
                string      column            = hlaGoal.ToString().Substring(0, 1) + i.ToString();
                HlaToLength hlaToLengthOrNull = HlaAssignmentParams.GetHlaToLengthValueOrNull(row, column, hlaResolution);
                if (hlaToLengthOrNull == null || hlaToLengthOrNull.HlaNumberToLength >= 9000)
                {
                    hasNull = true;
                    continue;
                }

                if (hlaGoal.ToString() == hlaToLengthOrNull.ToString())
                {
                    return(true);
                }
            }
            if (hasNull)
            {
                return(null);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        ////!!!same logic is elseware. Look for common heading
        //private static Dictionary<string, Dictionary<string, double>> LoadReactTableUnfiltered(TextReader patientReader, out Set<string> cidsInReactTable)
        //{
        //    cidsInReactTable = Set<string>.GetInstance();

        //    Dictionary<string, Dictionary<string, double>> reactTable = new Dictionary<string, Dictionary<string, double>>();
        //    string header = "peptide	cid	magnitude";
        //    foreach (Dictionary<string, string> row in SpecialFunctions.TabFileTable(patientReader, header, false))
        //    {
        //        string cid = row["cid"];
        //        cidsInReactTable.AddNewOrOld(cid);
        //        string peptide = row["peptide"];
        //        double amount = double.Parse(row["magnitude"]);

        //        Dictionary<string, double> peptideToAmount = SpecialFunctions.GetValueOrDefault(reactTable, peptide);
        //        peptideToAmount.Add(cid, amount);
        //    }
        //    return reactTable;
        //}

        private Dictionary <string, Set <Hla> > LoadKnownTable(DbDataReader datareader, string caseName)
        {
            //!!!code appears elsewhere. Look for common header
            Dictionary <string, Set <Hla> > knownTable = new Dictionary <string, Set <Hla> >();

            int indexPeptide = datareader.GetOrdinal("peptide");
            int indexHLA     = datareader.GetOrdinal("knownHLA");

            int irecord = 0;

            while (datareader.Read())
            {
                ++irecord;

                string peptide = datareader.GetString(indexPeptide).Trim();
                string hlaName = datareader.GetString(indexHLA).Trim();

                if (peptide.Length == 0 || hlaName.Length == 0)
                {
                    continue;
                }

                Set <Hla> knownHlaSet = SpecialFunctions.GetValueOrDefault(knownTable, peptide);
                Hla       hla         = HlaFactory.GetGroundInstance(hlaName);
                SpecialFunctions.CheckCondition(!knownHlaSet.Contains(hla), string.Format("Hla {0} is duplicated in {1}known.txt, for peptide {2}", hla, caseName, peptide));
                knownHlaSet.AddNew(hla); //!!!const
            }

            Console.WriteLine("{0}: number of records read: {1}", "Known table", irecord);

            return(knownTable);
        }
        public static IsHla24 GetInstance(Hla hla)
        {
            IsHla24 isHla24 = new IsHla24();

            isHla24.Hla24 = FindHla24(hla);
            return(isHla24);
        }
        private static string FindHla24(Hla hla)
        {
            string hlaName = hla.ToString();

            hlaName = hlaName.Replace("*", "");
            if (hlaName.StartsWith("HLA"))
            {
                hlaName = hlaName.Substring(3);
            }
            if (hlaName.StartsWith(" ") || hlaName.StartsWith("-"))
            {
                hlaName = hlaName.Substring(1);
            }
            SpecialFunctions.CheckCondition(hlaName.Length == 5, "Expect hla to contain a class letter and a 4-digit number. " + hla.ToString());
            SpecialFunctions.CheckCondition(hlaName[0] == 'A' || hlaName[0] == 'B' || hlaName[0] == 'C', "Expect hla to contain a class letter: A,B, or C. " + hla.ToString());
            int ignore;

            SpecialFunctions.CheckCondition(int.TryParse(hlaName.Substring(1), out ignore), "Expect hla to contain a 4-digit number. " + hla.ToString());

            string hla24;

            if (hlaName.StartsWith("A68") || hlaName.StartsWith("B15"))
            {
                hla24 = hlaName;
            }
            else
            {
                hla24 = hlaName.Substring(0, 3);
            }
            return(hla24);
        }
        internal static IsSupertypeFromWorkingDirectory GetInstance(Hla hla)
        {
            IsSupertypeFromWorkingDirectory isSupertypeFromWorkingDirectory = new IsSupertypeFromWorkingDirectory();

            isSupertypeFromWorkingDirectory.SupertypeFromWorkingDirectory = VirusCount.HlaToLength.ToSupertypeFromWorkingDirectoryString(hla.ToString());
            return(isSupertypeFromWorkingDirectory);
        }
        //!!!very similar to other code
        public static Dictionary <Pair <NEC, Hla>, bool> ReadTable(HlaFactory hlaFactory, string fileName, bool dedup)
        {
            Dictionary <Pair <NEC, Hla>, bool> table = new Dictionary <Pair <NEC, Hla>, bool>();

            foreach (Dictionary <string, string> row in SpecialFunctions.TabFileTable(fileName, "N\tepitope\tC\thla\tlabel", false))
            {
                string n       = row["N"];
                string epitope = row["epitope"];
                SpecialFunctions.CheckCondition(Biology.GetInstance().LegalPeptide(epitope), string.Format("Peptide, '{0}', contains illegal char.", epitope));
                string c           = row["C"];
                NEC    nec         = NEC.GetInstance(n, epitope, c);
                Hla    hla         = hlaFactory.GetGroundInstance(row["hla"]);
                string labelString = row["label"];
                SpecialFunctions.CheckCondition(labelString == "0" || labelString == "1", "Expect label to be '0' or '1'");
                Pair <NEC, Hla> pair        = new Pair <NEC, Hla>(nec, hla);
                bool            labelAsBool = (labelString == "1");
                if (dedup && table.ContainsKey(pair))
                {
                    SpecialFunctions.CheckCondition(table[pair] == labelAsBool, "The example " + pair.ToString() + " appears with contradictory labels.");
                    continue;
                }
                table.Add(pair, labelAsBool);
            }
            return(table);
        }
        internal static IsZero6SupertypeNoBlanks GetInstance(Hla hla)
        {
            IsZero6SupertypeNoBlanks isZero6SupertypeNoBlanks = new IsZero6SupertypeNoBlanks();

            isZero6SupertypeNoBlanks.Zero6SupertypeNoBlanks = VirusCount.HlaToLength.ToZero6SupertypeNoBlanksString(hla.ToString());
            return(isZero6SupertypeNoBlanks);
        }
        internal static IsZero6Supertype GetInstance(Hla hla)
        {
            IsZero6Supertype isZero6Supertype = new IsZero6Supertype();

            isZero6Supertype.Zero6Supertype = VirusCount.HlaToLength.ToZero6SupertypeBlanksString(hla.ToString());
            return(isZero6Supertype);
        }
        public static IsHla GetInstance(Hla hla)
        {
            IsHla isHla = new IsHla();

            isHla.Hla = hla.ToString();
            return(isHla);
        }
コード例 #12
0
        public override Hla GetGroundOrAbstractInstance(string name)
        {
            Hla hla = new Hla();

            hla.Name = name;
            return(hla);
        }
 private void FlipListedBits(Set <Hla> assignmentAsSet, List <int> indexList)
 {
     foreach (int index in indexList)
     {
         Hla hlaOfRepondingPatients = QmmrModelOnePeptide.QmrrModelMissingAssignment.SwitchableHlasOfRespondingPatients[index];
         BitFlip(assignmentAsSet, hlaOfRepondingPatients);
     }
 }
        internal static IsSupertypeFromFile GetInstance(Hla hla, string filePrefix, Assembly assembly, string resourcePrefix)
        {
            IsSupertypeFromFile isSupertypeFromFile = new IsSupertypeFromFile();

            isSupertypeFromFile.FilePrefix     = filePrefix;
            isSupertypeFromFile.Supertype      = LookupSupertypeFromFile(hla.ToString(), filePrefix, assembly, resourcePrefix);
            isSupertypeFromFile.Assembly       = assembly;
            isSupertypeFromFile.ResourcePrefix = resourcePrefix;
            return(isSupertypeFromFile);
        }
 private static void BitFlip(Set <Hla> assignmentAsSet, Hla hlaOfRepondingPatients)
 {
     if (assignmentAsSet.Contains(hlaOfRepondingPatients))
     {
         assignmentAsSet.Remove(hlaOfRepondingPatients);
     }
     else
     {
         assignmentAsSet.AddNew(hlaOfRepondingPatients);
     }
 }
コード例 #16
0
 public override bool IsMoreGeneralThan(Hla hla)
 {
     SpecialFunctions.CheckCondition(!IsGround && hla.IsGround, "IsMoreGeneralThan is only defined between an abstract and ground hla");
     foreach (var nameAndOri in NameAndOriList)
     {
         if (IsMoreGeneralOrEqualThan(nameAndOri.Key, hla.Name))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #17
0
        internal static HlaAssignmentWithResponses GetInstance(Quickscore <Hla, int> quickscore, List <Hla> hlaListFromRepondingPatients, List <int> indexCollection,
                                                               Dictionary <Hla, List <int> > hlaToRespondingPatients)
        {
            List <Hla> trueCollection = new List <Hla>();

            foreach (int index in indexCollection)
            {
                Hla hla = hlaListFromRepondingPatients[index];
                trueCollection.Add(hla);
            }
            return(HlaAssignmentWithResponses.GetInstance(trueCollection, quickscore, hlaListFromRepondingPatients, hlaToRespondingPatients));
        }
コード例 #18
0
        private static void CreateAndAddHlaFeature(bool subtractHlaFeatures, Hla hla, Pair <NEC, Hla> necAndHla, ref Set <IHashableFeature> hlaishEnumeration)
        {
            if (subtractHlaFeatures)
            {
                return;
            }

            IsHla featureHla = IsHla.GetInstance(hla);

            hlaishEnumeration.AddNew(featureHla);
            Debug.Assert((bool)featureHla.Evaluate(necAndHla)); // real assert - must only generate true features
        }
コード例 #19
0
        public static Dictionary <Hla, List <int> > Filter9xs(Dictionary <Hla, List <int> > hlaToRespondingPatientsUnfiltered)
        {
            Debug.Fail("Confirm that is function is still useful after the 'string'->Qmrr.String conversion");
            Dictionary <Hla, List <int> > filtered = new Dictionary <Hla, List <int> >();

            foreach (KeyValuePair <Hla, List <int> > hlaAndPatientList in hlaToRespondingPatientsUnfiltered)
            {
                Hla hla = hlaAndPatientList.Key;
                if (!nineXs.IsMatch(hla.ToString()))
                {
                    filtered.Add(hla, hlaAndPatientList.Value);
                }
            }
            return(filtered);
        }
        internal override Dictionary <Hla, PValueDetails> CreateHlaToPValueDetails(int nullIndex, string peptide, Dictionary <string, Set <Hla> > pidToHlaSetAll, Set <Hla> setOfHlasToConsiderAdding, TextWriter writer)
        {
            Dictionary <Hla, PValueDetails> hlaToPValueDetails = new Dictionary <Hla, PValueDetails>();

            if (setOfHlasToConsiderAdding.Count == 0)
            {
                return(hlaToPValueDetails);
            }

            Dictionary <string, double> pidToReactValue = ReactTableUnfiltered[peptide];

            Set <Hla> knownHlaSet = KnownTable(peptide);

            SpecialFunctions.CheckCondition(setOfHlasToConsiderAdding.Intersection(knownHlaSet).Count == 0);

            Set <Hla> bestHlaSetSoFar = Set <Hla> .GetInstance();

            while (setOfHlasToConsiderAdding.Count > 0)
            {
                BestSoFar <PValueDetails, Hla> bestHlaToAddSoFar = BestSoFar <PValueDetails, Hla> .GetInstance(delegate(PValueDetails pValueDetails1, PValueDetails pValueDetails2) { return(pValueDetails1.Diff.CompareTo(pValueDetails2.Diff)); });

                foreach (Hla hla in setOfHlasToConsiderAdding) //!!!only look at hla's of patients with reactivity to this peptide (how effects nulls?)
                {
                    PValueDetails pValueDetails = CreateAPValueDetail(nullIndex, peptide, pidToHlaSetAll, knownHlaSet, bestHlaSetSoFar, hla);
                    bestHlaToAddSoFar.Compare(pValueDetails, hla);
                }
                //Debug.WriteLine("");
                PValueDetails bestPValueDetails = bestHlaToAddSoFar.ChampsScore; //!!!weird that PValue details is the score and the object

                if (bestPValueDetails.PValue() > PValueCutOff)
                {
                    break;
                }

                Hla hlaToAdd = bestHlaToAddSoFar.Champ;

                setOfHlasToConsiderAdding.Remove(hlaToAdd);
                bestHlaSetSoFar = bestHlaSetSoFar.Union(hlaToAdd);

                hlaToPValueDetails.Add(hlaToAdd, bestPValueDetails);
                writer.WriteLine(bestPValueDetails);
                //Debug.WriteLine(bestPValueDetails);
                writer.Flush();
            }
            return(hlaToPValueDetails);
        }
コード例 #21
0
        public static void UnitTest()
        {
            HlaMsr1Factory   hlaMsr1Factory = HlaMsr1Factory.GetFactory(new int[] { 4, 4, 4 });
            HashSet <string> warningSet     = new HashSet <string>();

            SpecialFunctions.CheckCondition(hlaMsr1Factory.GetGroundOrAbstractInstance("B*1234/B23", ref warningSet).ToString() == "B1234/B23");
            hlaMsr1Factory.GetGroundOrAbstractInstance("BND", ref warningSet);
            Hla hla5 = hlaMsr1Factory.GetGroundOrAbstractInstance("B", ref warningSet);

            SpecialFunctions.CheckCondition(hla5.ToString() == "B");
            Hla hla3 = hlaMsr1Factory.GetGroundOrAbstractInstance("C1234", ref warningSet);

            SpecialFunctions.CheckCondition(hla3.ToString() == "C1234");
            SpecialFunctions.CheckCondition(hlaMsr1Factory.GetGroundOrAbstractInstance("B*1234", ref warningSet).ToString() == "B1234");
            SpecialFunctions.CheckCondition(hlaMsr1Factory.GetGroundOrAbstractInstance("C1234/C12/C", ref warningSet).ToString() == "C");
            Hla hla7 = hlaMsr1Factory.GetGroundOrAbstractInstance("C1234N", ref warningSet);

            SpecialFunctions.CheckCondition(hla7.ToString() == "C1234");
            Hla hla6 = hlaMsr1Factory.GetGroundOrAbstractInstance("C12", ref warningSet);

            SpecialFunctions.CheckCondition(hla6.ToString() == "C12");
            Hla hla1 = hlaMsr1Factory.GetGroundOrAbstractInstance("A74", ref warningSet);

            SpecialFunctions.CheckCondition(hla1.ToString() == "A74");
            Hla hla2 = hlaMsr1Factory.GetGroundOrAbstractInstance("A7412", ref warningSet);

            SpecialFunctions.CheckCondition(hla2.ToString() == "A74");
            SpecialFunctions.CheckCondition(hla6.IsMoreGeneralThan(hla7));  // assert
            SpecialFunctions.CheckCondition(!hla6.IsMoreGeneralThan(hla2)); // assert
            SpecialFunctions.CheckCondition(hlaMsr1Factory.GetGroundOrAbstractInstance("A12345678", ref warningSet).ToString() == "A1234");
            SpecialFunctions.CheckCondition(hlaMsr1Factory.GetGroundOrAbstractInstance("B95", ref warningSet).ToString() == "B15");
            SpecialFunctions.CheckCondition(hlaMsr1Factory.GetGroundOrAbstractInstance("B15/B9512", ref warningSet).ToString() == "B15");
            Hla hla4 = hlaMsr1Factory.GetGroundOrAbstractInstance("A02/A9299", ref warningSet);

            SpecialFunctions.CheckCondition(hla4.ToString() == "A02");
            SpecialFunctions.CheckCondition(hla3.IsGround);  // assert
            SpecialFunctions.CheckCondition(hla1.IsGround);  // assert
            SpecialFunctions.CheckCondition(!hla4.IsGround); // assert
            SpecialFunctions.CheckCondition(!hla5.IsGround); // assert
            SpecialFunctions.CheckCondition(hlaMsr1Factory.GetGroundOrAbstractInstance("A1200", ref warningSet).ToString() == "A12");
            SpecialFunctions.CheckCondition(!hlaMsr1Factory.GetGroundOrAbstractInstance("B*1234/B23", ref warningSet).IsGround);
        }
コード例 #22
0
        //private Dictionary<string, bool> GetAList(Dictionary<string, string> row)
        //{
        //    Dictionary<string, bool> alist = new Dictionary<string, bool>();
        //    string alistValue = row["HLA In Fixed List"];
        //    foreach (string hla in alistValue.Split(' '))
        //    {
        //        Debug.Assert((hla.Length == 3 && !hla.StartsWith("B15")) || (hla.Length == 5 && hla.StartsWith("B15")));
        //        alist.Add(hla, true);
        //    }
        //    return alist;
        //}

        public static HlaAssignmentWithResponses CreateHlaAssignment(List <Dictionary <string, string> > rowsOfThisPeptide, IEnumerable <Hla> hlaList, HlaResolution hlaResolution, Quickscore <Hla, int> quickscore, List <int> patientsWhoRespond)
        {
            //!!!this code is repeated elsewhere
            Dictionary <Hla, List <int> > hlaToRespondingPatientsUnfiltered = quickscore.CreateCauseToSubsetOfEffects(patientsWhoRespond);
            Dictionary <Hla, List <int> > hlaToRespondingPatients           = Filter9xs(hlaToRespondingPatientsUnfiltered);
            List <Hla> hlaListFromRepondingPatients = new List <Hla>(hlaToRespondingPatients.Keys);

            Dictionary <Hla, bool> hlaAssignmentDicationary = new Dictionary <Hla, bool>();

            foreach (Dictionary <string, string> causeAssignmentRow in rowsOfThisPeptide)
            {
                Hla hla = GetHlaFromRow(causeAssignmentRow, hlaResolution);
                hlaAssignmentDicationary[hla] = true;
            }

            HlaAssignmentWithResponses hlaAssignment = HlaAssignmentWithResponses.GetInstance(hlaAssignmentDicationary.Keys, quickscore, hlaListFromRepondingPatients,
                                                                                              hlaToRespondingPatients);

            return(hlaAssignment);
        }
コード例 #23
0
        public static Quickscore <Hla, int> CreateQuickscore(string fileName, string header, double causePrior, double linkProbability, double leakProbability, HlaResolution hlaResolution)
        {
            Qmrr.HlaFactory hlaFactory = Qmrr.HlaFactory.GetFactory("noConstraint");

            Quickscore <Hla, int> quickscore = Quickscore <Hla, int> .GetInstance(hlaFactory.GetGroundInstance(""));


            foreach (Dictionary <string, string> row in QuickScoreOptimalsTable(fileName, header))
            {
                foreach (string column in CreateHlaColumns(header))
                {
                    Hla hla     = GetHlaValue(row, column, hlaResolution);
                    int patient = GetPatient(row);

                    quickscore.SetCause(hla, causePrior);
                    quickscore.SetLeak(patient, leakProbability);
                    quickscore.SetLink(hla, patient, linkProbability);
                }
            }
            return(quickscore);
        }
コード例 #24
0
        internal static PValueDetails GetInstance(
            string selectionName,
            int nullIndex, string peptide, Hla hla,
            double score1, double score2, Set <Hla> knownHlas, Set <Hla> bestHlaSetSoFar, double leakProbability, double linkProbability, OptimizationParameterList previousParams)
        {
            PValueDetails pValueDetails = new PValueDetails();

            pValueDetails.SelectionName   = selectionName;
            pValueDetails.NullIndex       = nullIndex;
            pValueDetails.Peptide         = peptide;
            pValueDetails.Hla             = hla;
            pValueDetails.Score1          = score1;
            pValueDetails.Score2          = score2;
            pValueDetails.Diff            = score1 - score2;
            pValueDetails.KnownHlas       = knownHlas;
            pValueDetails.BestHlaSetSoFar = bestHlaSetSoFar;
            pValueDetails.LeakProbability = leakProbability;
            pValueDetails.LinkProbability = linkProbability;
            pValueDetails.PreviousParams  = previousParams;
            return(pValueDetails);
        }
コード例 #25
0
        internal void SetPeptideToFitUniverse(string dataset)
        {
            Qmrr.HlaFactory hlaFactory = Qmrr.HlaFactory.GetFactory("noConstraint");

            PeptideToFitUniverse = new Dictionary <string, Set <Hla> >();
            string filename = dataset + "supertypefit.txt";
            string line     = null;

            //!!!would be nice to read as a tab table, to remove redundent lines, to check that HLAs are of the right form
            using (StreamReader streamReader = File.OpenText(filename))
            {
                while (null != (line = streamReader.ReadLine()))
                {
                    string[] fields = line.Split('\t');
                    SpecialFunctions.CheckCondition(fields.Length == 2);
                    string    peptide     = fields[0];
                    Hla       hla         = hlaFactory.GetGroundInstance(fields[1]);
                    Set <Hla> fitUniverse = SpecialFunctions.GetValueOrDefault(PeptideToFitUniverse, peptide);
                    fitUniverse.AddNewOrOld(hla);
                }
            }
        }
コード例 #26
0
        public override bool IsMoreGeneralThan(Hla hla)
        {
            Debug.Assert(!IsGround);                       // real assert

            SpecialFunctions.CheckCondition(hla.IsGround); //We only have code for this
            Debug.Assert(hla.Name.Length != 0 && Name.Length != 0);
            if (Name[0] != hla.Name[0])
            {
                return(false);
            }

            string otherRest = hla.Name.Substring(1);

            foreach (string rest in Name.Substring(1).Split('/'))
            {
                bool thisMatch = true;
                foreach (KeyValuePair <char, char> abstractCharAndGroundChar in SpecialFunctions.EnumerateTwo(rest, otherRest))
                {
                    char abstractChar = abstractCharAndGroundChar.Key;
                    char groundChar   = abstractCharAndGroundChar.Value;
                    if (abstractChar != '?')
                    {
                        if (abstractChar != groundChar)
                        {
                            thisMatch = false;
                            break;
                        }
                    }
                }

                if (thisMatch)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #27
0
        //!!!Yikes tons of repeated code and stuff re-run
        public static HlaAssignmentWithResponses CreateHlaAssignment(List <Dictionary <string, string> > rowsOfThisPeptide, IEnumerable <Hla> hlaList, HlaResolution hlaResolution, Quickscore <Hla, int> quickscore, List <int> patientsWhoRespond, Hla hlaToReplace, Hla hlaWithWhichToReplaceItOrNull)
        {
            //!!!this code is repeated elsewhere
            Dictionary <Hla, List <int> > hlaToRespondingPatientsUnfiltered = quickscore.CreateCauseToSubsetOfEffects(patientsWhoRespond);
            Dictionary <Hla, List <int> > hlaToRespondingPatients           = Filter9xs(hlaToRespondingPatientsUnfiltered);
            List <Hla> hlaListFromRepondingPatients = new List <Hla>(hlaToRespondingPatients.Keys);

            Dictionary <Hla, bool> hlaAssignmentDicationary = new Dictionary <Hla, bool>();

            foreach (Dictionary <string, string> causeAssignmentRow in rowsOfThisPeptide)
            {
                Hla hla = GetHlaFromRow(causeAssignmentRow, hlaResolution);
                hlaAssignmentDicationary[hla] = true;
            }
            hlaAssignmentDicationary.Remove(hlaToReplace);
            if (hlaWithWhichToReplaceItOrNull != null)
            {
                hlaAssignmentDicationary.Add(hlaWithWhichToReplaceItOrNull, true);
            }

            List <int> indexCollection = new List <int>();

            for (int hlaIndex = 0; hlaIndex < hlaListFromRepondingPatients.Count; ++hlaIndex)
            {
                Hla hla = hlaListFromRepondingPatients[hlaIndex];
                if (hlaAssignmentDicationary.ContainsKey(hla))
                {
                    indexCollection.Add(hlaIndex);
                }
            }

            HlaAssignmentWithResponses hlaAssignment = HlaAssignmentWithResponses.GetInstance(quickscore, hlaListFromRepondingPatients,
                                                                                              indexCollection, hlaToRespondingPatients);

            return(hlaAssignment);
        }
コード例 #28
0
        static public IEnumerable <Hla> FindAllHla(List <Dictionary <string, string> > expandedTable, HlaResolution hlaResolution, string header)
        {
            Qmrr.HlaFactory hlaFactory = Qmrr.HlaFactory.GetFactory("noConstraint");

            Dictionary <Hla, bool> seenIt = new Dictionary <Hla, bool>();

            foreach (Dictionary <string, string> row in expandedTable)
            {
                foreach (string column in HlaAssignmentParams.CreateHlaColumns(header))
                {
                    HlaToLength hlaToLengthOrNull = HlaAssignmentParams.GetHlaToLengthValueOrNull(row, column, hlaResolution);
                    if (hlaToLengthOrNull == null || hlaToLengthOrNull.HlaNumberToLength >= 9000)
                    {
                        continue;
                    }
                    Hla hla = hlaFactory.GetGroundInstance(hlaToLengthOrNull.ToString());
                    if (!seenIt.ContainsKey(hla))
                    {
                        seenIt.Add(hla, true);
                        yield return(hla);
                    }
                }
            }
        }
コード例 #29
0
ファイル: AOPTests2.cs プロジェクト: superliujian/Sxta
 public void OnReceiveUpdateAttributeValues(Hla.Rti1516.IObjectInstanceHandle instanceHandle, string methodName, object newValue)
 {
     name = methodName;
     val = newValue;
     Sxta.Rti1516.HLAAttributes.HLAobjectRoot obj = registedObjects[instanceHandle] as Sxta.Rti1516.HLAAttributes.HLAobjectRoot;
     if (log.IsDebugEnabled)
     {
         log.Debug("The method " + methodName + " has been called; new value:" + newValue + "; parameter type = " + newValue.GetType());
         log.Debug("The object is " + obj);
     }
 }
コード例 #30
0
ファイル: AOPTests.cs プロジェクト: superliujian/Sxta
 public void OnReceiveUpdateAttributeValues(Hla.Rti1516.IObjectInstanceHandle instanceHandle, string methodName, object newValue)
 {
     name = methodName;
     val = newValue;
     if (log.IsDebugEnabled)
         log.Debug("The method " + methodName + " has been called; new value:" + newValue + "; parameter type = " + newValue.GetType());
 }
コード例 #31
0
ファイル: AOPTests2.cs プロジェクト: superliujian/Sxta
 public object RegistedObject(Hla.Rti1516.IObjectInstanceHandle handle)
 {
     return registedObjects[handle];
 }
        private PValueDetails CreateAPValueDetail(int nullIndex, string peptide, Dictionary <string, Set <Hla> > pidToHlaSetAll, Set <Hla> knownHlaSet, Set <Hla> bestHlaSetSoFar, Hla hla)
        {
            //Dictionary<string, Dictionary<string, double>> reactTableCustom;
            Dictionary <string, Set <Hla> > pidToHlaSetCustom =
                CreatePidToHlaSetCustom(pidToHlaSetAll, bestHlaSetSoFar, hla, knownHlaSet);
            //out pidToHlaSetCustom, out reactTableCustom);

            //!!!could cache both calls to FindBestParams
            double scoreBase;
            OptimizationParameterList baseParams = FindBestParams(peptide, bestHlaSetSoFar, Set <Hla> .GetInstance(), pidToHlaSetCustom, out scoreBase);

            double scoreWithOneMore;
            OptimizationParameterList withMoreMoreParams = FindBestParams(peptide, bestHlaSetSoFar.Union(hla), Set <Hla> .GetInstance(), pidToHlaSetCustom, out scoreWithOneMore);

            PValueDetails pValueDetails = PValueDetails.GetInstance(SelectionName, nullIndex, peptide, hla,
                                                                    scoreWithOneMore, scoreBase, knownHlaSet, bestHlaSetSoFar, withMoreMoreParams["leakProbability"].Value, withMoreMoreParams["link" + hla].Value, withMoreMoreParams);

            //Debug.Write(String.Format("{0}/{1}\t", hla, scoreWithOneMore));
            return(pValueDetails);
        }
        //!!!this could be made faster by keeping track of patients with no abstract hlas
        private Dictionary <string, Set <Hla> > CreatePidToHlaSetCustom(Dictionary <string, Set <Hla> > pidToHlaSetAll, Set <Hla> bestHlaSetSoFar, Hla hla, Set <Hla> knownHlaSet
                                                                        //out Dictionary<string, Set<Hla>> pidToHlaSetCustom,
                                                                        //out Dictionary<string, Dictionary<string, double>> reactTableCustom
                                                                        )
        {
            Set <Hla> possibleCauses = bestHlaSetSoFar.Union(knownHlaSet);

            possibleCauses.AddNewOrOld(hla);

#if DEBUG
            foreach (Hla hlaPossibleCause in possibleCauses)
            {
                Debug.Assert(hlaPossibleCause.IsGround); // real assert
            }
#endif

            Dictionary <string, Set <Hla> > pidToHlaSetCustom = new Dictionary <string, Set <Hla> >();
            //reactTableCustom = new Dictionary<string, Dictionary<string, double>>();

            foreach (string pid in pidToHlaSetAll.Keys)
            {
                Set <Hla> patientHlaSet = pidToHlaSetAll[pid];


                //bestSoFar/known Hla PidContains ExcludePid?
                //B23   B25 B15??   No
                //B23   B1511   B15??   Yes

                if (!ThisPatientContainsAnAbstractHlaThatGeneralizesAPossibleCause(patientHlaSet, possibleCauses))
                {
                    pidToHlaSetCustom.Add(pid, patientHlaSet);
                    // reactTableCustom.Add(pid, ReactTableUnfiltered[pid]);
                }
                else
                {
                    //Debug.WriteLine(SpecialFunctions.CreateTabString(patientHlaSet, possibleCauses));
                }
            }

            return(pidToHlaSetCustom);
        }