/// <summary> /// Imports sequence features. /// </summary> /// <param name="metadata"> /// The metadata. /// </param> /// <param name="sequence"> /// The sequence. /// </param> /// <returns> /// Returns tuple where first element is import result text /// and second element is import status as string. /// </returns> private (string, string) ImportFeatures(GenBankMetadata metadata, CommonSequence sequence) { try { using (var subsequenceImporter = new SubsequenceImporter(metadata.Features.All, sequence.Id)) { var(featuresCount, nonCodingCount) = subsequenceImporter.CreateSubsequences(); string result = $"Successfully imported sequence, {featuresCount} features " + $"and {nonCodingCount} non-coding subsequences"; string status = "Success"; return(result, status); } } catch (Exception exception) { string result = $"successfully imported sequence but failed to import genes: {exception.Message}"; while (exception.InnerException != null) { exception = exception.InnerException; result += $" {exception.Message}"; } string status = "Error"; return(result, status); } }
public ActionResult Index(long[] matterIds) { return(CreateTask(() => { string[] matterNames; var results = new string[matterIds.Length]; var statuses = new string[matterIds.Length]; using (var db = new LibiadaWebEntities()) { matterNames = db.Matter .Where(m => matterIds.Contains(m.Id)) .OrderBy(m => m.Id) .Select(m => m.Name) .ToArray(); var parentSequences = db.DnaSequence .Where(c => matterIds.Contains(c.MatterId)) .OrderBy(c => c.MatterId) .ToArray(); for (int i = 0; i < parentSequences.Length; i++) { try { DnaSequence parentSequence = parentSequences[i]; using (var subsequenceImporter = new SubsequenceImporter(parentSequence)) { subsequenceImporter.CreateSubsequences(); } int featuresCount = db.Subsequence.Count(s => s.SequenceId == parentSequence.Id && s.Feature != Feature.NonCodingSequence); int nonCodingCount = db.Subsequence.Count(s => s.SequenceId == parentSequence.Id && s.Feature == Feature.NonCodingSequence); statuses[i] = "Success"; results[i] = $"Successfully imported {featuresCount} features and {nonCodingCount} non coding subsequences"; } catch (Exception exception) { statuses[i] = "Error"; results[i] = exception.Message; while (exception.InnerException != null) { results[i] += $" {exception.InnerException.Message}"; exception = exception.InnerException; } } } } return new Dictionary <string, object> { { "matterNames", matterNames }, { "results", results }, { "status", statuses } }; })); }
public ActionResult Index(long matterId) { return(CreateTask(() => { Dictionary <string, object> result; using (var db = new LibiadaWebEntities()) { DnaSequence parentSequence = db.DnaSequence.Single(d => d.MatterId == matterId); using (var subsequenceImporter = new SubsequenceImporter(parentSequence)) { subsequenceImporter.CreateSubsequences(); } var features = EnumExtensions.ToArray <Feature>().ToDictionary(f => (byte)f, f => f.GetDisplayValue()); string matterName = db.Matter.Single(m => m.Id == matterId).Name; SubsequenceData[] sequenceSubsequences = db.Subsequence .Where(s => s.SequenceId == parentSequence.Id) .Include(s => s.Position) .ToArray() .Select(s => new SubsequenceData(s)) .ToArray(); result = new Dictionary <string, object> { { "matterName", matterName }, { "genes", sequenceSubsequences }, { "features", features } }; } return new Dictionary <string, object> { { "data", JsonConvert.SerializeObject(result) } }; })); }
public ActionResult Index(long[] matterIds) { return(CreateTask(() => { string[] matterNames; var importResults = new List <MatterImportResult>(matterIds.Length); using (var db = new LibiadaWebEntities()) { matterNames = Cache.GetInstance().Matters .Where(m => matterIds.Contains(m.Id)) .OrderBy(m => m.Id) .Select(m => m.Name) .ToArray(); var parentSequences = db.DnaSequence .Where(c => matterIds.Contains(c.MatterId)) .OrderBy(c => c.MatterId) .ToArray(); for (int i = 0; i < parentSequences.Length; i++) { var importResult = new MatterImportResult() { MatterName = matterNames[i] }; try { DnaSequence parentSequence = parentSequences[i]; using (var subsequenceImporter = new SubsequenceImporter(parentSequence)) { subsequenceImporter.CreateSubsequences(); } int featuresCount = db.Subsequence.Count(s => s.SequenceId == parentSequence.Id && s.Feature != Feature.NonCodingSequence); int nonCodingCount = db.Subsequence.Count(s => s.SequenceId == parentSequence.Id && s.Feature == Feature.NonCodingSequence); importResult.Status = "Success"; importResult.Result = $"Successfully imported {featuresCount} features and {nonCodingCount} non coding subsequences"; importResults.Add(importResult); } catch (Exception exception) { importResult.Status = "Error"; importResult.Result = exception.Message; while (exception.InnerException != null) { importResult.Result += $" {exception.InnerException.Message}"; exception = exception.InnerException; } importResults.Add(importResult); } } } var result = new Dictionary <string, object> { { "result", importResults } }; return new Dictionary <string, string> { { "data", JsonConvert.SerializeObject(result) } }; })); }