public List <SampleRecord> GetSampleData() { List <SampleRecord> records = new List <SampleRecord>(); using (StreamReader sr = new StreamReader(truthFile)) { while (true) { string line = sr.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } string[] splat = line.Split('\t'); if (splat[0] == "SUBJID") { continue; } SampleRecord newRec = new SampleRecord(); newRec.SubjectId = splat[0].Trim(); newRec.SangerResult = splat[1].Trim(); newRec.TherascreenResult = splat[2].Trim(); newRec.Valid = (splat[3] == "VALID"); records.Add(newRec); } return(records); } }
public SampleTruth ApplyRule(SampleRecord sampleTruthRecord) { SampleTruth sampleTruthInfor = new SampleTruth(sampleTruthRecord.SubjectId); InitiateSampleTruth(sampleTruthInfor); //check the therascreen result //if (sampleTruthRecord.TherascreenResult.ToUpper().Equals("INVALID")) // Console.WriteLine($"sample thereascreen result is {sampleTruthRecord.TherascreenResult}\t in {sampleTruthRecord.SubjectId}"); if (sampleTruthRecord.TherascreenResult.ToUpper().Equals("WT")) { setTherascreenResultWT(sampleTruthInfor); } else { //since therascreen contain name like 12ASP and 12ASP dectected string[] theraNameItems = sampleTruthRecord.TherascreenResult.Split(); string mutationTheraName = "KRAS_" + theraNameItems[0]; if (AminoAcidToBaseChangeForTherascreenDictionary.ContainsKey(mutationTheraName)) { setSangerResultIgnored(sampleTruthInfor); setPartMutationStatus(sampleTruthInfor, "K2", "PASS"); List <string> mutationNames = AminoAcidToBaseChangeForTherascreenDictionary[mutationTheraName]; foreach (var mutationName in mutationNames) { SetValueForDetectedTruthMutation(sampleTruthInfor, mutationName, mutationTheraName); } } else if (!sampleTruthRecord.TherascreenResult.ToUpper().Equals("INVALID")) { throw new Exception("unrecogonized therascreen result: {sampleTruthRecord.TherascreenResult}"); } } //check the sanger result // Console.WriteLine($"sample sanger result is {sampleTruthRecord.SangerResult}\t in {sampleTruthRecord.SubjectId}"); string[] sangerResultItems = sampleTruthRecord.SangerResult.Split(','); if (sangerResultItems.Length == 2) { if (sangerResultItems[0].Trim().StartsWith("WT") && sangerResultItems[1].Trim().StartsWith("FAIL")) { setSangerResultWT(sampleTruthInfor); string failParts = sangerResultItems[1].Trim().Substring(4); if (failParts.Length < 2) { throw new Exception($"unrecogonized therascreen result: {sampleTruthRecord.SangerResult}"); } char GeneParts = failParts[0]; failParts = failParts.Remove(0, 1); while (failParts.Length > 0) { char currentChar = failParts[0]; if (currentChar >= '0' && currentChar <= '9') { char[] failChars = new char[2]; failChars[0] = GeneParts; failChars[1] = currentChar; string failPart = new string(failChars); setPartMutationStatus(sampleTruthInfor, failPart.ToUpper(), "FAIL"); } else if ((currentChar >= 'A' && currentChar <= 'Z') || (currentChar >= 'a' && currentChar <= 'z')) { GeneParts = currentChar; } failParts = failParts.Remove(0, 1); } } else { throw new Exception($"unrecogonized therascreen result: {sampleTruthRecord.SangerResult}"); } } else if (sangerResultItems.Length == 1) { //ignore NA case, since already processed when dealing with therascreen result if (sampleTruthRecord.SangerResult.ToUpper().Equals("NA")) { //continue } else if (sampleTruthRecord.SangerResult.ToUpper().Equals("WT")) { setSangerResultWT(sampleTruthInfor); } else if (sampleTruthRecord.SangerResult.ToUpper().Equals("FAIL")) { //need this case, in case of therascreen detected mutation but Sanger was performed and failed (unlikely) setSangerResultFail(sampleTruthInfor); } else { //detected a mutation or other unrecognized result if (AminoAcidToBaseChangeForSangerDictionary.ContainsKey(sampleTruthRecord.SangerResult)) { setSangerResultWT(sampleTruthInfor); List <string> mutationNames = AminoAcidToBaseChangeForSangerDictionary[sampleTruthRecord.SangerResult]; foreach (var mutationName in mutationNames) { SetValueForDetectedTruthMutation(sampleTruthInfor, mutationName, sampleTruthRecord.SangerResult); } } else { throw new Exception($"unrecogonized sanger result: {sampleTruthRecord.SangerResult}"); } } } else { throw new Exception($"unrecogonized sanger result: {sampleTruthRecord.SangerResult}"); } return(sampleTruthInfor); }