public async Task <IEnumerable <SynthesisActivityItemViewModel> > GetCurrentSynthesisActivities() { GeneSynthesisProcess currentGeneSynthesisProcess = await GetCurrentGeneSynthesisProcess(); if (currentGeneSynthesisProcess?.GeneSynthesisActivities != null && currentGeneSynthesisProcess.GeneSynthesisActivities.Any()) { IList <SynthesisActivityItemViewModel> currentSynthesisActivities = new List <SynthesisActivityItemViewModel>(); foreach (GeneSynthesisActivity geneSynthesisActivity in currentGeneSynthesisProcess.GeneSynthesisActivities) { SynthesisActivityItemViewModel synthesisActivityItemViewModel = new SynthesisActivityItemViewModel(); synthesisActivityItemViewModel.Id = geneSynthesisActivity.Id; synthesisActivityItemViewModel.ChannelNumber = geneSynthesisActivity.ChannelNumber; synthesisActivityItemViewModel.DNASequence = geneSynthesisActivity.DNASequence; synthesisActivityItemViewModel.TotalTime = geneSynthesisActivity.TotalTime; synthesisActivityItemViewModel.SynthesisCycle = new SynthesisCycleItemViewModel() { Id = geneSynthesisActivity.SynthesisCycle.Id, Name = geneSynthesisActivity.SynthesisCycle.Name }; currentSynthesisActivities.Add(synthesisActivityItemViewModel); } return(currentSynthesisActivities); } return(Enumerable.Empty <SynthesisActivityItemViewModel>()); }
public async Task UpdateSynthesisProcess(GeneSynthesisProcessViewModel viewModel) { GeneSynthesisProcess entity = await GetCurrentGeneSynthesisProcess(); entity.DenaturationTempGeneAssembly = viewModel.DenaturationTempGeneAssembly; entity.DenaturationTimeGeneAssembly = viewModel.DenaturationTimeGeneAssembly; entity.AnnealingTempGeneAssembly = viewModel.AnnealingTempGeneAssembly; entity.AnnealingTimeGeneAssembly = viewModel.AnnealingTimeGeneAssembly; entity.ElongationTempGeneAssembly = viewModel.ElongationTempGeneAssembly; entity.ElongationTimeGeneAssembly = viewModel.ElongationTimeGeneAssembly; entity.DenaturationTempGeneAmplification = viewModel.DenaturationTempGeneAmplification; entity.DenaturationTimeGeneAmplification = viewModel.DenaturationTimeGeneAmplification; entity.AnnealingTempGeneAmplification = viewModel.AnnealingTempGeneAmplification; entity.AnnealingTimeGeneAmplification = viewModel.AnnealingTimeGeneAmplification; entity.ElongationTempGeneAmplification = viewModel.ElongationTempGeneAmplification; entity.ElongationTimeGeneAmplification = viewModel.ElongationTimeGeneAmplification; entity.NumberOfGeneAssemblyCycles = viewModel.NumberOfGeneAssemblyCycles; entity.NumberOfGeneAmplificationCycles = viewModel.NumberOfGeneAmplificationCycles; CalcGeneSynthesisProcessTotalTime(entity); unitOfWork.Commit(); }
public GeneSynthesisProcess CreateGeneSynthesisProcess() { var geneSynthesisProcess = new GeneSynthesisProcess(); geneSynthesisProcess.Gene = CreateGene(); return(GetOrCreate(() => geneSynthesisProcess)); }
public async Task DeleteSynthesisProcess(string id) { GeneSynthesisProcess currentGeneSynthesisProcess = await GetCurrentGeneSynthesisProcess(); currentGeneSynthesisProcess.Deleted = true; unitOfWork.Commit(); }
private async Task ChangeSynthesisProcessStatus(SynthesisProcessStatus newStatus) { GeneSynthesisProcess currentGeneSynthesisProcess = await GetCurrentGeneSynthesisProcess(); currentGeneSynthesisProcess.Status = newStatus; unitOfWork.InsertOrUpdate(currentGeneSynthesisProcess); unitOfWork.Commit(); }
public async Task <GeneSynthesisProcessViewModel> GetCurrentSynthesisProcess() { GeneSynthesisProcessViewModel geneSynthesisProcessViewModel; GeneSynthesisProcess currentGeneSynthesisProcess = await GetCurrentGeneSynthesisProcess(); if (currentGeneSynthesisProcess != null) { geneSynthesisProcessViewModel = new GeneSynthesisProcessViewModel() { Id = currentGeneSynthesisProcess.Id, GeneId = currentGeneSynthesisProcess.GeneId, Status = currentGeneSynthesisProcess.Status, TotalTime = currentGeneSynthesisProcess.TotalTime, SelectedGeneId = currentGeneSynthesisProcess.GeneId, DenaturationTempGeneAssembly = currentGeneSynthesisProcess.DenaturationTempGeneAssembly, DenaturationTimeGeneAssembly = currentGeneSynthesisProcess.DenaturationTimeGeneAssembly, AnnealingTempGeneAssembly = currentGeneSynthesisProcess.AnnealingTempGeneAssembly, AnnealingTimeGeneAssembly = currentGeneSynthesisProcess.AnnealingTimeGeneAssembly, ElongationTempGeneAssembly = currentGeneSynthesisProcess.ElongationTempGeneAssembly, ElongationTimeGeneAssembly = currentGeneSynthesisProcess.ElongationTimeGeneAssembly, DenaturationTempGeneAmplification = currentGeneSynthesisProcess.DenaturationTempGeneAmplification, DenaturationTimeGeneAmplification = currentGeneSynthesisProcess.DenaturationTimeGeneAmplification, AnnealingTempGeneAmplification = currentGeneSynthesisProcess.AnnealingTempGeneAmplification, AnnealingTimeGeneAmplification = currentGeneSynthesisProcess.AnnealingTimeGeneAmplification, ElongationTempGeneAmplification = currentGeneSynthesisProcess.ElongationTempGeneAmplification, ElongationTimeGeneAmplification = currentGeneSynthesisProcess.ElongationTimeGeneAmplification, NumberOfGeneAssemblyCycles = currentGeneSynthesisProcess.NumberOfGeneAssemblyCycles, NumberOfGeneAmplificationCycles = currentGeneSynthesisProcess.NumberOfGeneAmplificationCycles, }; } else { geneSynthesisProcessViewModel = new GeneSynthesisProcessViewModel() { Status = SynthesisProcessStatus.NotStarted, SelectedGeneId = "", }; } User currentUser = GetCurrentUser(); IEnumerable <Gene> allGenes = await unitOfWork.GetAll <Gene>() .Where(x => x.UserId == currentUser.Id) .ToListAsync(); geneSynthesisProcessViewModel.AllGenes = allGenes.Select(x => new ListItem() { Id = x.Id, Text = x.Name }); return(geneSynthesisProcessViewModel); }
private async Task <GeneSynthesisProcess> GetCurrentGeneSynthesisProcess() { var currentPrincipal = identityStorage.GetPrincipal(); GeneSynthesisProcess geneSynthesisProcess = await unitOfWork.GetAll <GeneSynthesisProcess>() .Include(x => x.Gene.User) .Include(x => x.GeneSynthesisActivities.Select(y => y.SynthesisCycle.CycleSteps)) .Where(x => !x.Deleted && x.Gene.UserId == currentPrincipal.UserId && (x.Status == SynthesisProcessStatus.NotStarted || x.Status == SynthesisProcessStatus.InProgress || x.Status == SynthesisProcessStatus.Suspended)) .FirstOrDefaultAsync(); return(geneSynthesisProcess); }
private void CalcGeneSynthesisProcessTotalTime(GeneSynthesisProcess geneSynthesisProcess) { int totalTimeActivities = geneSynthesisProcess.GeneSynthesisActivities.Sum(x => x.TotalTime); int totalTimeGeneAssembly = (geneSynthesisProcess.DenaturationTimeGeneAssembly + geneSynthesisProcess.AnnealingTimeGeneAssembly + geneSynthesisProcess.ElongationTimeGeneAssembly) * geneSynthesisProcess.NumberOfGeneAssemblyCycles; int totalTimeGeneAmplification = (geneSynthesisProcess.DenaturationTimeGeneAmplification + geneSynthesisProcess.AnnealingTimeGeneAmplification + geneSynthesisProcess.ElongationTimeGeneAmplification) * geneSynthesisProcess.NumberOfGeneAmplificationCycles; geneSynthesisProcess.TotalTime = totalTimeActivities + totalTimeGeneAssembly + totalTimeGeneAmplification; }
public async Task CreateGeneSynthesisProcess(string geneId) { Gene gene = await unitOfWork.GetAll <Gene>().Include(x => x.GeneFragments).SingleAsync(x => x.Id == geneId); await AssertGeneFragmentsCorrespondsToConfiguredChannels(gene.GeneFragments); GeneSynthesisProcess currentGeneSynthesisProcess = await GetCurrentGeneSynthesisProcess(); if (currentGeneSynthesisProcess != null) { currentGeneSynthesisProcess.Deleted = true; } GeneSynthesisProcess newGeneSynthesisProcess = new GeneSynthesisProcess { Status = SynthesisProcessStatus.NotStarted, Gene = gene, }; unitOfWork.InsertOrUpdate(newGeneSynthesisProcess); unitOfWork.Commit(); // create synthesis activities from gene fragments SynthesisCycle defaultSynthesisCycle = await unitOfWork.GetAll <SynthesisCycle>() .Include(x => x.CycleSteps) .SingleAsync(x => x.UserId == null); IList <GeneSynthesisActivity> geneSynthesisActivities = new List <GeneSynthesisActivity>(); foreach (GeneFragment geneFragment in gene.GeneFragments) { GeneSynthesisActivity newSynthesisActivity = await CreateSynthesisActivity(geneFragment.OligoSequence, newGeneSynthesisProcess, defaultSynthesisCycle); geneSynthesisActivities.Add(newSynthesisActivity); } await AssignChannelNumbers(geneSynthesisActivities); await unitOfWork.InsertAll(geneSynthesisActivities); newGeneSynthesisProcess.TotalTime = geneSynthesisActivities.Sum(x => x.TotalTime); unitOfWork.Commit(); }
private async Task <GeneSynthesisActivity> CreateSynthesisActivity( string dnaSequence, GeneSynthesisProcess currentGeneSynthesisProcess, SynthesisCycle defaultSynthesisCycle) { GeneSynthesisActivity geneSynthesisActivity = new GeneSynthesisActivity(); geneSynthesisActivity.GeneSynthesisProcessId = currentGeneSynthesisProcess.Id; geneSynthesisActivity.GeneSynthesisProcess = currentGeneSynthesisProcess; geneSynthesisActivity.SynthesisCycleId = defaultSynthesisCycle.Id; geneSynthesisActivity.SynthesisCycle = defaultSynthesisCycle; geneSynthesisActivity.DNASequence = !string.IsNullOrWhiteSpace(dnaSequence) ? dnaSequence.ToUpper() : "A"; CalcGeneSynthesisActivityTotalTime(geneSynthesisActivity); return(geneSynthesisActivity); }
public async Task CreateOrUpdateSynthesisActivity(SynthesisActivityItemViewModel item) { GeneSynthesisActivity entity; GeneSynthesisProcess currentGeneSynthesisProcess = await GetCurrentGeneSynthesisProcess(); if (string.IsNullOrWhiteSpace(item.Id)) { entity = new GeneSynthesisActivity(); entity.GeneSynthesisProcess = currentGeneSynthesisProcess; } else { entity = await unitOfWork.GetAll <GeneSynthesisActivity>() .Include(x => x.SynthesisCycle) .Include(x => x.GeneSynthesisProcess) .SingleAsync(x => x.Id == item.Id); } entity.DNASequence = !string.IsNullOrWhiteSpace(item.DNASequence) ? item.DNASequence.ToUpper() : "A"; if (item.SynthesisCycle != null && !string.IsNullOrWhiteSpace(item.SynthesisCycle.Id)) { entity.SynthesisCycle = unitOfWork.GetById <SynthesisCycle>(item.SynthesisCycle.Id); } else { SynthesisCycle defaultSynthesisCycle = await unitOfWork.GetAll <SynthesisCycle>() .SingleAsync(x => x.UserId == null); entity.SynthesisCycle = defaultSynthesisCycle; } await AssignToChannel(entity, currentGeneSynthesisProcess.GeneSynthesisActivities); CalcGeneSynthesisActivityTotalTime(entity); unitOfWork.InsertOrUpdate(entity); unitOfWork.Commit(); currentGeneSynthesisProcess = await GetCurrentGeneSynthesisProcess(); CalcGeneSynthesisProcessTotalTime(currentGeneSynthesisProcess); unitOfWork.Commit(); }
private async Task StartGeneSynthesisProcess() { ICloudTable <GeneSynthesisProcess> geneSynthesisProcessTable = null; GeneSynthesisProcess currentGeneSynthesisProcess = null; try { await AwaitPreviousSynthesisProcess(); LogAction("Syncing gene synthesis process..."); var currentUserId = GetCurrentUserId(); await CloudService.SyncOfflineCacheAsync(); LogAction("Sync completed."); geneSynthesisProcessTable = await CloudService.GetTableAsync <GeneSynthesisProcess>(); var allGeneSynthesisProcesses = await geneSynthesisProcessTable.ReadAllItemsAsync(); currentGeneSynthesisProcess = allGeneSynthesisProcesses.Where(x => x.Gene.UserId == currentUserId) .OrderByDescending(x => x.CreatedAt) .FirstOrDefault(); if (currentGeneSynthesisProcess == null) { LogAction("Gene synthesis process not found."); } var hardwareFunctionTable = await CloudService.GetTableAsync <HardwareFunction>(); var allHardwareFunctions = await hardwareFunctionTable.ReadAllItemsAsync(); IEnumerable <HardwareFunction> bAndTetToColFunctions = allHardwareFunctions.Where( x => x.FunctionType == HardwareFunctionType.AAndTetToCol || x.FunctionType == HardwareFunctionType.CAndTetToCol || x.FunctionType == HardwareFunctionType.TAndTetToCol || x.FunctionType == HardwareFunctionType.GAndTetToCol); HardwareFunction closeAllValvesFunction = allHardwareFunctions.Single(x => x.FunctionType == HardwareFunctionType.CloseAllValves); SynthesisProcessTotalTime = currentGeneSynthesisProcess.TotalTime; MessagingCenter.Send <LogsViewModel>(this, "SynthesisProcessStarted"); int geneSynthesisProcessRemainingTime = currentGeneSynthesisProcess.TotalTime; LogAction($"Starting a new gene synthesis process. Total Time: {geneSynthesisProcessRemainingTime} s"); foreach (GeneSynthesisActivity geneSynthesisActivity in currentGeneSynthesisProcess.GeneSynthesisActivities.OrderBy(x => x.ChannelNumber)) { int oligoSynthesisActivityTotalTime = geneSynthesisActivity.TotalTime; await Task.Run(async() => { await oligoSynthesizerRestService.StartSynthesis(geneSynthesisActivity, bAndTetToColFunctions, closeAllValvesFunction, oligoSynthesisActivityTotalTime); }); geneSynthesisProcessRemainingTime -= oligoSynthesisActivityTotalTime; LogAction($"Total remaining time: {geneSynthesisProcessRemainingTime} s"); } //currentOligoSynthesisProcess.Status = SynthesisProcessStatus.Completed; //await oligoSynthesisProcessTable.UpdateItemAsync(currentOligoSynthesisProcess); } catch (Exception ex) { //currentOligoSynthesisProcess.Status = SynthesisProcessStatus.Failed; //await oligoSynthesisProcessTable.UpdateItemAsync(currentOligoSynthesisProcess); LogAction($"Gene synthesis process failed: {ex.Message}"); } finally { await CloudService.SyncOfflineCacheAsync(); } }