//!!!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);
        }
Пример #2
0
        public static Hla GetHlaValue(Dictionary <string, string> row, string column, HlaResolution hlaResolution)
        {
            HlaToLength hlaToLength = GetHlaToLengthValueOrNull(row, column, hlaResolution);

            SpecialFunctions.CheckCondition(hlaToLength != null);
            return(HlaFactory.GetGroundInstance(hlaToLength.ToString()));
        }
Пример #3
0
 private void ReadKnownTable()
 {
     _knownTable = new Dictionary <string, Set <Hla> >();
     if (OptimizationParameterList["useKnownList"].Value == 1)
     {
         foreach (Dictionary <string, string> row in SpecialFunctions.TabFileTable(KnownFileName, "peptide	knownHLA", false))    //!!!const
         {
             string    peptide     = row["peptide"];                                                                          //!!!const
             Set <Hla> knownHlaSet = SpecialFunctions.GetValueOrDefault(_knownTable, peptide);
             knownHlaSet.AddNew(HlaFactory.GetGroundInstance(row["knownHLA"]));                                               //!!!const
         }
     }
 }
        private static Hla GetHlaFromRow(Dictionary <string, string> causeAssignmentRow, HlaResolution hlaResolution)
        {
            Qmrr.HlaFactory hlaFactory = Qmrr.HlaFactory.GetFactory("noConstraint");

            string hla = causeAssignmentRow["HLA"];

            if (hla.Length == 4 || hla.Length == 2)             //!!!should this be moved to GetHlaLengthInstance so doesn't appear twice?
            {
                hla = hla.Substring(0, 1) + "0" + hla.Substring(1);
            }

            HlaToLength hlaToLength = hlaResolution.GetHlaLengthInstance(hla);

            SpecialFunctions.CheckCondition(hlaToLength != null);
            return(hlaFactory.GetGroundInstance(hlaToLength.ToString()));
        }
Пример #5
0
        private void ReadPatientTable()
        {
            Qmrr.HlaFactory hlaFactory = Qmrr.HlaFactory.GetFactory("noConstraint");


            PatientList = new Dictionary <string, Set <Hla> >();
            foreach (Dictionary <string, string> row in SpecialFunctions.TabFileTable(PatientFileName, "pid	a1	a2	b1	b2	c1	c2", false))                        //!!!const
            {
                string    patientId = row["pid"];
                Set <Hla> hlaList   = new Set <Hla>();
                foreach (string columnName in new string[] { "a1", "a2", "b1", "b2", "c1", "c2" })                //!!!const
                {
                    hlaList.AddNewOrOld(hlaFactory.GetGroundInstance(row[columnName]));
                }
                PatientList.Add(patientId, hlaList);
            }
        }
Пример #6
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);
        }
Пример #7
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);
                }
            }
        }
        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);
                    }
                }
            }
        }