protected override void Seed(TCRContext context) { base.Seed(context); //if (System.Diagnostics.Debugger.IsAttached == false) // Для отладки / for debugging // System.Diagnostics.Debugger.Launch(); context.Receptors.RemoveRange(context.Receptors); context.People.RemoveRange(context.People); context.VSegments.RemoveRange(context.VSegments); context.DSegments.RemoveRange(context.DSegments); context.JSegments.RemoveRange(context.JSegments); context.SaveChanges(); context.Configuration.AutoDetectChangesEnabled = false; FillVSegments(context); FillDSegments(context); FillJSegments(context); string[] files = Directory.GetFiles(ConfigurationManager.AppSettings["InitDataPath"], "*.tcr"); for (int i = 0; i < files.Length; ++i) { string name = "Person" + (i + 1).ToString(); Person person = new Person { FirstName = name, MiddleName = name, LastName = name }; context.People.Add(person); context.SaveChanges(); FileStream fileStream = new FileStream(files[i], FileMode.Open); StreamReader reader = new StreamReader(fileStream); string curStr = null; reader.ReadLine(); // Пропускаем названия столбцов/ Shifting columns' names while ((curStr = reader.ReadLine()) != null) { string[] fields = curStr.Split('\t'); string nucleoSeq = fields[2]; Receptor receptor = context.Receptors.FirstOrDefault(r => r.NucleoSequence == nucleoSeq); if (receptor == null) { receptor = new Receptor { NucleoSequence = fields[2], AminoSequence = fields[3], LastVNucleoPos = Convert.ToInt32(fields[7]), FirstDNucleoPos = Convert.ToInt32(fields[8]), LastDNucleoPos = Convert.ToInt32(fields[9]), FirstJNucleoPos = Convert.ToInt32(fields[10]), VDInsertions = Convert.ToInt32(fields[11]), DJInsertions = Convert.ToInt32(fields[12]), TotalInsertions = Convert.ToInt32(fields[13]) }; FillSegments(context, fields, receptor); context.Receptors.Add(receptor); context.SaveChanges(); } context.PersonalReceptors.Add(new PersonalReceptor { ReadCount = Convert.ToInt32(fields[0]), Percentage = Convert.ToDouble(fields[1], new NumberFormatInfo() { NumberDecimalSeparator = "." }), Receptor = receptor, Person = person }); context.SaveChanges(); } } }
private static void FillSegments(TCR.Models.TCRContext context, string[] fields, Receptor receptor) { string[] alleles = fields[4].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries); foreach (string allele in alleles) { VSegment segment = context.VSegments.First(s => s.Alleles == allele); receptor.VSegments.Add(segment); } alleles = fields[6].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries); foreach (string allele in alleles) { DSegment segment = context.DSegments.First(s => s.Alleles == allele); receptor.DSegments.Add(segment); } alleles = fields[5].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries); foreach (string allele in alleles) { JSegment segment = context.JSegments.First(s => s.Alleles == allele); receptor.JSegments.Add(segment); } }