Beispiel #1
0
 public patient_result_collections AddCollection(patient patient, result_files file)
 {
     // Add the patient result collection for this entry
     var collection = new patient_result_collections()
     {
         patient_id = patient.id,
         received_on = DateTime.Now,
         result_file_id = file.id
     };
     entities.patient_result_collections.Add(collection);
     entities.SaveChanges();
     return collection;
 }
Beispiel #2
0
        protected result_files AddResultFile(string filePath, result_sources source)
        {
            string hash = GetFileHash(filePath);

            var file = new result_files()
            {
                md5 = hash,
                name = filePath,
                received_on = DateTime.Now,
                result_source_id = source.id
            };
            return fileRepo.AddResultFile(file);
        }
Beispiel #3
0
        public patient_result_collections AddResult(patient patient, result_files file, string name, string value, string externalId, string externalSource, DateTime resultedOn)
        {
            // First, identify the reference phenotype and if it exists
            var phenotype = (from pheno in entities.phenotypes
                             where pheno.name == name && pheno.value == value
                             select pheno).FirstOrDefault();
            if (phenotype == null)
            {
                phenotype = new phenotype()
                {
                    name = name,
                    value = value,
                    external_source = externalSource,
                    external_id = externalId
                };
                entities.phenotypes.Add(phenotype);
                entities.SaveChanges();
            }

            // Now add the patient phenotype
            var patientPhenotype = new patient_phenotypes()
            {
                phenotype = phenotype,
                resulted_on = resultedOn
            };
            entities.patient_phenotypes.Add(patientPhenotype);
            entities.SaveChanges();

            // Add the patient result collection for this entry
            var collection = patientRepo.AddCollection(patient, file);

            // Finally, link the collection to the phenotype
            var member = new patient_result_members()
            {
                collection_id = collection.id,
                member_id = patientPhenotype.id,
                member_type = Enums.ResultMemberType.Phenotype,
            };

            entities.patient_result_members.Add(member);
            entities.SaveChanges();

            return collection;
        }
Beispiel #4
0
        public patient_result_collections AddSnps(patient patient, result_files file, DateTime resultedOn, List<SnpResult> snps)
        {
            // Create a collection
            var collection = patientRepo.AddCollection(patient, file);

            // Create patient variant entries
            List<patient_variants> variants = new List<patient_variants>();
            foreach (var snp in snps)
            {
                var variant = GetVariant(snp.RSID, "dbSNP", snp.Position, snp.Position);
                var patientVariant = new patient_variants()
                {
                    patient_id = patient.id,
                    variant_type = Enums.PatientVariantType.SNP,
                    reference_id = variant.id,
                    resulted_on = resultedOn,
                    value1 = snp.Genotype[0].ToString(),
                    value2 = snp.Genotype[1].ToString()
                };
                variants.Add(patientVariant);
            }
            entities.patient_variants.AddRange(variants);
            entities.SaveChanges();

            // Finally, link the collection to the SNPs
            foreach (var variant in variants)
            {
                var member = new patient_result_members()
                {
                    collection_id = collection.id,
                    member_id = variant.id,
                    member_type = Enums.ResultMemberType.Variant,
                };
                entities.patient_result_members.Add(member);
            }
            entities.SaveChanges();

            return collection;
        }
Beispiel #5
0
        public patient_result_collections AddStarVariants(patient patient, result_files file, DateTime resultedOn, List<StarVariantResult> stars)
        {
            // Create a collection
            var collection = patientRepo.AddCollection(patient, file);

            // Create patient variant entries
            List<patient_variants> variants = new List<patient_variants>();
            foreach (var star in stars)
            {
                var gene = AddGene(star.Gene, star.Gene, null, null, null);
                var variant = AddVariant(star.Gene, star.Result, "Star Variant", null, null, null, null, null);
                string[] splitStars = star.Result.Split(new string[]{"*"}, StringSplitOptions.RemoveEmptyEntries);
                var patientVariant = new patient_variants()
                {
                    patient_id = patient.id,
                    variant_type = Enums.PatientVariantType.StarVariant,
                    reference_id = variant.id,
                    resulted_on = resultedOn,
                    value1 = splitStars[0],
                    value2 = splitStars[1]
                };
                variants.Add(patientVariant);
            }

            entities.patient_variants.AddRange(variants);
            entities.SaveChanges();

            // Finally, link the collection to the stars
            foreach (var variant in variants)
            {
                var member = new patient_result_members()
                {
                    collection_id = collection.id,
                    member_id = variant.id,
                    member_type = Enums.ResultMemberType.Variant,
                };
                entities.patient_result_members.Add(member);
            }
            entities.SaveChanges();

            return collection;
        }
Beispiel #6
0
 public result_files AddResultFile(result_files file)
 {
     entities.result_files.Add(file);
     entities.SaveChanges();
     return file;
 }
        private List<string> GetPhenotypeDetails(result_files file, string phenotype)
        {
            List<string> details = new List<string>();
            var geneIds = GetGeneFilterForPhenotype(phenotype);
            if (geneIds == null)
            {
                return details;
            }

            foreach (var collection in file.patient_result_collections)
            {
                foreach (var member in collection.patient_result_members)
                {
                    switch (member.member_type)
                    {
                        case Enums.ResultMemberType.Phenotype:
                            var patientPhenotype = entities.patient_phenotypes.Where(x => x.id == member.member_id).FirstOrDefault();
                            details.Add(string.Format("<div>The phenotype {0} {1} was resulted on {2} <small>{3} {4}</small></div>",
                                patientPhenotype.phenotype.name, patientPhenotype.phenotype.value, patientPhenotype.resulted_on.Value.ToShortDateString(), patientPhenotype.phenotype.external_source, patientPhenotype.phenotype.external_id));
                            break;
                        case Enums.ResultMemberType.Variant:
                            StringBuilder builder = new StringBuilder();
                            var patientVariant = entities.patient_variants.Where(x => x.id == member.member_id).FirstOrDefault();
                            variant variant = null;
                            switch (patientVariant.variant_type)
                            {
                                case Enums.PatientVariantType.SNP:
                                    variant = entities.variants.Where(x =>
                                        x.id == patientVariant.reference_id && x.gene_id.HasValue && geneIds.Contains(x.gene_id.Value)).FirstOrDefault();
                                    if (variant != null)
                                    {
                                        builder.AppendFormat("<div class='variant'>{0}: ", variant.external_id);
                                        builder.AppendFormat("<span class='{0}'>{1}</span>",
                                            variant.reference_bases == patientVariant.value1 ? "normal" : "alternate",
                                            patientVariant.value1);
                                        builder.AppendFormat("<span class='{0}'>{1}</span>",
                                            variant.reference_bases == patientVariant.value2 ? "normal" : "alternate",
                                            patientVariant.value2);
                                        builder.AppendFormat("<small>On chr{0}, Reference is {1} from {2}</small></div>", variant.chromosome, variant.reference_bases, variant.reference_genome);
                                    }
                                    break;
                                case Enums.PatientVariantType.StarVariant:
                                    variant = entities.variants.Where(x =>
                                        x.id == patientVariant.reference_id && x.gene_id.HasValue && geneIds.Contains(x.gene_id.Value)).FirstOrDefault();
                                    if (variant != null)
                                    {
                                        builder.AppendFormat("<div class='variant'>{0}: ", variant.gene.name);
                                        builder.AppendFormat("<span class='{0}'>*{1}</span>/",
                                            "1" == patientVariant.value1 ? "normal" : "alternate",
                                            patientVariant.value1);
                                        builder.AppendFormat("<span class='{0}'>{1}</span>",
                                            "1" == patientVariant.value2 ? "normal" : "alternate",
                                            patientVariant.value2);
                                    }
                                    break;
                                case Enums.PatientVariantType.Collection:
                                    break;
                                default:
                                    details.Add(string.Format("The variant type {0} for variant {1} could not be displayed", patientVariant.variant_type, patientVariant.reference_id));
                                    break;
                            }
                            details.Add(builder.ToString());
                            //details.Add(string.Format("<div>{0} = {1}{2} ({3})</div>", formattedVariant, patientVariant.value1, patientVariant.value2, patientVariant.resulted_on.Value.ToShortDateString()));
                            break;
                    }
                }
            }

            return details;
        }