public patient AddPatient(string mrn, string mrnSource, string firstName, string lastName, DateTime? dateOfBirth) { var result = (from existingPatient in entities.patients where existingPatient.external_source == mrnSource && existingPatient.external_id == mrn select existingPatient).FirstOrDefault(); if (result == null) { patient newPatient = new patient() { external_source = mrnSource, external_id = mrn, date_of_birth = dateOfBirth, first_name = firstName, last_name = lastName }; entities.patients.Add(newPatient); entities.SaveChanges(); result = newPatient; } return result; }
public result_entities AddPhenotype(result_files resultFile, patient patient, attribute attribute, DateTime? resultedOn) { result_entities rootEntity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = attribute.id, }; result_entities resultedOnEntity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = GetAttribute(null, null, "Resulted on", null).id, parent = rootEntity, value_date_time = resultedOn }; entities.result_entities.AddRange(new[] { rootEntity, resultedOnEntity }); entities.SaveChanges(); return rootEntity; }
public override void LoadData(string filePath) { var vcfParser = new VCFParser(filePath); var header = vcfParser.Header; var patient = new patient(); var source = sourceRepo.AddSource("VCF", "VCF file"); var file = AddResultFile(filePath, source); // Process the file-level pragmas result_entities rootEntity = new result_entities() { attribute_id = EntityRepository.GetAttribute(null, null, "Variant Call Format result", null).id, result_file_id = file.id }; // We pull out all of the metadata from the header (all lines) and write them as information // lines associated with this result. var headerEntities = new List<result_entities>(); foreach (var headerItem in header.MetaDataInInputOrder) { if (headerItem.Key == "individual-id") { var individualParts = headerItem.Value.Replace("<", "").Replace(">", "").Split(new char[] { ',' }); var individualData = individualParts.Select(x => x.Split(new char[] { '=' })).ToArray(); var mrnParts = individualData.FirstOrDefault(x => x[0] == "Dbxref")[1].Split(':'); patient = patientRepo.AddPatient(mrnParts[1], mrnParts[0], individualData.FirstOrDefault(x => x[0] == "First_name")[1], individualData.FirstOrDefault(x => x[0] == "Last_name")[1], DateTime.Parse(individualData.FirstOrDefault(x => x[0] == "DOB")[1])); } else if (headerItem.Key == "fileDate") { DateTime resultDate = DateTime.ParseExact(headerItem.Value, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None); headerEntities.Add(CreateEntityAttribute("Resulted on", 0, file.id, rootEntity, resultDate.ToShortDateString())); } else if (headerItem.GetType() == typeof(VCFInfoHeaderLine)) { var info = headerItem as VCFInfoHeaderLine; var infoEntity = CreateEntityAttribute("INFO", 0, file.id, rootEntity, null); headerEntities.Add(infoEntity); headerEntities.Add(CreateEntityAttribute("ID", 0, file.id, infoEntity, info.ID)); headerEntities.Add(CreateEntityAttribute("Number", 0, file.id, infoEntity, info.CountType.ToString())); headerEntities.Add(CreateEntityAttribute("Type", 0, file.id, infoEntity, info.Type.ToString())); headerEntities.Add(CreateEntityAttribute("Description", 0, file.id, infoEntity, info.Description)); } else if (headerItem.GetType() == typeof(VCFFilterHeaderLine)) { var filter = headerItem as VCFFilterHeaderLine; var filterEntity = CreateEntityAttribute("FILTER", 0, file.id, rootEntity, null); headerEntities.Add(filterEntity); foreach (var field in filter.GenericFields()) { headerEntities.Add(CreateEntityAttribute(field.Key, 0, file.id, filterEntity, field.Value)); } } else if (headerItem.GetType() == typeof(VCFFormatHeaderLine)) { var format = headerItem as VCFFormatHeaderLine; var formatEntity = CreateEntityAttribute("FORMAT", 0, file.id, rootEntity, null); headerEntities.Add(formatEntity); headerEntities.Add(CreateEntityAttribute("ID", 0, file.id, formatEntity, format.ID)); headerEntities.Add(CreateEntityAttribute("Number", 0, file.id, formatEntity, format.CountType.ToString())); headerEntities.Add(CreateEntityAttribute("Type", 0, file.id, formatEntity, format.Type.ToString())); headerEntities.Add(CreateEntityAttribute("Description", 0, file.id, formatEntity, format.Description)); } else { var headerEntity = CreateEntityAttribute(headerItem.Key, 0, file.id, rootEntity, headerItem.Value); headerEntities.Add(headerEntity); } } rootEntity.patient_id = patient.id; headerEntities.ForEach(x => x.patient_id = patient.id); var variantEntities = new List<result_entities>(); while (vcfParser.MoveNext()) { var current = vcfParser.Current; result_entities variantEntity = new result_entities() { attribute_id = EntityRepository.GetAttribute(null, null, "Variant Call Format variant", null).id, result_file_id = file.id, patient_id = patient.id, parent = rootEntity }; variantEntities.Add(variantEntity); result_entities snpEntity = new result_entities() { attribute_id = EntityRepository.GetAttribute(current.ID, "dbSNP", null, null).id, result_file_id = file.id, patient_id = patient.id, parent = variantEntity }; variantEntities.Add(snpEntity); SetVariantValues(current, patient.id, file.id, snpEntity, variantEntities); variantEntities.Add(CreateEntityAttribute("Chromosome", patient.id, file.id, variantEntity, current.Chr)); variantEntities.Add(CreateEntityAttribute("Start position", patient.id, file.id, variantEntity, current.Start.ToString())); variantEntities.Add(CreateEntityAttribute("End position", patient.id, file.id, variantEntity, current.End.ToString())); variantEntities.Add(CreateEntityAttribute("Reference base", patient.id, file.id, variantEntity, current.Reference.BaseString)); variantEntities.Add(CreateEntityAttribute("Quality", patient.id, file.id, variantEntity, current.PhredScaledQual.ToString())); foreach (var attr in current.Attributes) { variantEntities.Add(CreateEntityAttribute(string.Format("INFO:{0}", attr.Key), patient.id, file.id, variantEntity, attr.Value.ToString())); } if (current.FiltersMaybeNull != null) { foreach (var filter in current.FiltersMaybeNull) { variantEntities.Add(CreateEntityAttribute(string.Format("FILTER:{0}", filter), patient.id, file.id, variantEntity, string.Empty)); } } //foreach (var genotype in current.Genotypes) //{ // attributeList.Add(AddVariantInformation("VCF:Genotype", genotype.ToMHGRString())); //} //attributeList.Add(AddVariantInformation("VCF:Quality", current.PhredScaledQual.ToString())); //attributeList.Add(AddVariantInformation("VCF:Filter", string.Join(",", current.Filters.ToArray()))); //featureInformationList.Add(patientVariant, attributeList); } entityRepo.AddVCF(rootEntity, headerEntities, variantEntities); }
public result_entities[] AddSnps(result_files resultFile, patient patient, DateTime? resultedOn, List<SnpResult> snps) { var results = new List<result_entities>(); var snpAlleleAttributeId = GetAttribute(null, null, "SNP allele", null).id; var referenceBaseAttributeId = GetAttribute(null, null, "Reference base", null).id; var resultedOnAttributeId = GetAttribute(null, null, "Resulted on", null).id; foreach (var snp in snps) { var entityParts = new List<result_entities>(); result_entities rootEntity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = GetAttribute(snp.RSID, "dbSNP", snp.RSID, snp.RSID).id, }; result_entities resultedOnEntity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = resultedOnAttributeId, parent = rootEntity, value_date_time = resultedOn }; result_entities referenceBaseEntity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = referenceBaseAttributeId, parent = rootEntity, value_short_text = snp.ReferenceBase }; result_entities allele1Entity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = snpAlleleAttributeId, parent = rootEntity, value_short_text = snp.Genotype[0].ToString() }; result_entities allele2Entity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = snpAlleleAttributeId, parent = rootEntity, value_short_text = snp.Genotype[1].ToString() }; entities.result_entities.AddRange(new[] { rootEntity, resultedOnEntity, referenceBaseEntity, allele1Entity, allele2Entity }); results.Add(rootEntity); } entities.SaveChanges(); return results.ToArray(); }
public result_entities[] AddStarVariants(patient patient, result_files resultFile, DateTime resultedOn, List<StarVariantResult> stars) { var results = new List<result_entities>(); foreach (var star in stars) { var entityParts = new List<result_entities>(); result_entities rootEntity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = GetAttribute(star.Gene, "HGNC", star.Gene, star.Gene).id }; entityParts.Add(rootEntity); result_entities resultedOnEntity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = GetAttribute(null, null, "Resulted on", null).id, parent = rootEntity, value_date_time = resultedOn }; entityParts.Add(resultedOnEntity); string[] splitStars = star.Result.Split(new string[] { "*" }, StringSplitOptions.RemoveEmptyEntries); foreach (var value in splitStars) { result_entities alleleEntity = new result_entities() { patient_id = patient.id, result_file_id = resultFile.id, attribute_id = GetAttribute(null, null, "Star allele", null).id, parent = rootEntity, value_short_text = value }; entityParts.Add(alleleEntity); } entities.result_entities.AddRange(entityParts); results.Add(rootEntity); } entities.SaveChanges(); return results.ToArray(); }