public ComparisonViewModelTestConductor(GenomeModel a = null, GenomeModel b = null)
 {
     View = new ComparisonViewModel(
         Favourites.Object,
         a ?? TestGenomeModel.Create(),
         b);
 }
        // GET: GenomeAssembly/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            GenomeModel genomeModel = db.GenomeModels.Find(id);

            if (genomeModel == null)
            {
                return(HttpNotFound());
            }

            string currentUser = User.Identity.Name;

            // Only let the user that created the job view that job.
            if (genomeModel.CreatedBy.Equals(currentUser))
            {
                if (!string.IsNullOrEmpty(genomeModel.DownloadLink))
                {
                    // We need to display the download link for the user which is set in CheckJobStatus.UploadData() and stored in the model
                    // under DownloadLink.
                }

                return(View(genomeModel));
            }

            else
            {
                return(RedirectToAction("DetailsPermissionError", "Error"));
            }
        }
Exemple #3
0
        public static bool IsAssemblyFinished(this GenomeModel genomeModel)
        {
            int assemblersFinished = 0;

            if (genomeModel.UseMasurca)
            {
                if (genomeModel.MasurcaCurrentStep.Equals(StepDescriptions.GetMasurcaStepList().Last().step))
                {
                    assemblersFinished++;
                }
            }

            if (genomeModel.UseSGA)
            {
            }

            if (genomeModel.UseWGS)
            {
            }

            if (assemblersFinished.Equals(genomeModel.NumberOfAssemblers))
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Updates the status of the masurca assembler. If it has either errored out (-1) or is completed (last step), it will not change the status.
        /// </summary>
        /// <param name="client">The current SSH client session.</param>
        /// <param name="genomeModel">The model of the particular job.</param>
        private static void CheckMasurcaStep(SshClient client, GenomeModel genomeModel)
        {
            if (string.IsNullOrEmpty(ErrorHandling.error) &&
                !genomeModel.MasurcaCurrentStep.Equals(-1) &&
                !genomeModel.MasurcaCurrentStep.Equals(StepDescriptions.GetMasurcaStepList().Last().step))
            {
                if (LinuxCommands.DirectoryHasFiles(client, Accessors.GetMasurcaOutputPath(genomeModel.Seed)))
                {
                    int currentMasurcaStep = LinuxCommands.GetCurrentStep(client, Accessors.GetMasurcaOutputPath(genomeModel.Seed), StepDescriptions.GetMasurcaStepList());

                    // Provided we didn't encounter an error, set the status of masurca and the job.
                    if (currentMasurcaStep != -1)
                    {
                        genomeModel.MasurcaCurrentStep = currentMasurcaStep;
                        genomeModel.MasurcaStatus      = StepDescriptions.GetCurrentStepDescription(StepDescriptions.GetMasurcaStepList(), currentMasurcaStep);
                    }

                    else
                    {
                        StepDescriptions.SetMasurcaError(client, genomeModel);
                    }
                }

                // Either masurca hasn't started or it has but no files have been created yet.
                else
                {
                    genomeModel.MasurcaCurrentStep = 1;
                    genomeModel.MasurcaStatus      = StepDescriptions.GetCurrentStepDescription(StepDescriptions.GetMasurcaStepList(), 1);
                }
            }
        }
 private IEnumerable <SnpViewModel> MakeSnpViewModels(GenomeModel a, GenomeModel b)
 {
     if (b == null)
     {
         foreach (var aa in a.Snp)
         {
             yield return(MakeSnpViewModel(aa, null));
         }
         yield break;
     }
     // SNP in genome A and SNP in both genome A and B.
     foreach (var aa in a.Snp)
     {
         SnpModel bb;
         b.Snp.TryGetById(aa.Id, out bb);
         yield return(MakeSnpViewModel(aa, bb));
     }
     // SNP only in genome B.
     foreach (var bb in b.Snp)
     {
         SnpModel _;
         if (a.Snp.TryGetById(bb.Id, out _))
         {
             continue;
         }
         yield return(MakeSnpViewModel(null, bb));
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComparisonViewModel"/> class.
        /// </summary>
        /// <param name="favouritesManager">The favourites manager.</param>
        /// <param name="a">The first gneome to compare.</param>
        /// <param name="b">The optional second genome to compare, can be <see langword="null"/>.</param>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown if <paramref name="favouritesManager"/> or <paramref name="a"/> is <see langword="null"/>.
        /// </exception>
        public ComparisonViewModel(IFavouritesManager favouritesManager, GenomeModel a, GenomeModel b = null)
        {
            Guard.IsNotNull(favouritesManager, nameof(favouritesManager));
            Guard.IsNotNull(a, nameof(a));

            _favouritesManager = favouritesManager;
            Snp = new SnpViewModelCollection(MakeSnpViewModels(a, b));
        }
        public ActionResult Details(int id, string command)
        {
            GenomeModel genomeModel = db.GenomeModels.Find(id);

            if (command == "Update Status" && string.IsNullOrEmpty(genomeModel.DownloadLink))
            {
                JobMaintenance.UpdateStatus(genomeModel);
            }

            if (command == "Cancel Job")
            {
                // Add a method in JobMaintenance that reflects cancelling a job. Best place for it.
            }

            db.SaveChanges();

            return(View(genomeModel));
        }
Exemple #8
0
        /// <summary>
        /// Sets default values if the user decided not to enter any information for optional values in the wizard.
        /// </summary>
        /// <param name="genomeModel">The model data for a particular job.</param>
        /// <returns>Returns the new job model with the default values.</returns>
        public static GenomeModel SetDefaultMasurcaValues(GenomeModel genomeModel)
        {
            // If they don't have jump reads.
            if (genomeModel.JumpReads == false)
            {
                genomeModel.JumpLength = 0;
            }

            // If they don't have paired-end reads.
            if (genomeModel.PEReads == false)
            {
                genomeModel.PairedEndLength = 0;
            }

            if (genomeModel.MasurcaMean == null)
            {
                genomeModel.MasurcaMean = 180;
            }

            if (genomeModel.MasurcaStdev == null)
            {
                genomeModel.MasurcaStdev = 20;
            }

            // We don't specify anything here. If it is null, we set it to AUTO in the masurca method of the config builder.
            if (genomeModel.MasurcaGraphKMerValue == null)
            {
                if (genomeModel.MasurcaKMerErrorCount == null)
                {
                    genomeModel.MasurcaKMerErrorCount = 1;
                }
            }

            if (genomeModel.MasurcaThreadNum == null)
            {
                genomeModel.MasurcaThreadNum = 20;
            }

            genomeModel.MasurcaCurrentStep = 1;
            genomeModel.MasurcaStatus      = StepDescriptions.GetCurrentStepDescription(StepDescriptions.GetMasurcaStepList(), 1);

            return(genomeModel);
        }
Exemple #9
0
        /// <summary>
        /// Updates the status of the job by appropriately increasing the step and changing the status.
        /// </summary>
        /// <param name="genomeModel">The model that represents the current job.</param>
        /// <param name="hasError">If there is an error during execution, it will set the current status of the job to an error state and sets the step number to the final step.</param>
        /// <param name="customErrorMsg">Instead of the default error messages associated with each step, you may list your own.</param>
        public static void NextStep(this GenomeModel genomeModel, bool hasError = false, string customErrorMsg = "")
        {
            if (hasError)
            {
                if (string.IsNullOrWhiteSpace(customErrorMsg))
                {
                    genomeModel.OverallStatus = GetOverallStepErrors()[genomeModel.OverallCurrentStep].ToString();
                }

                else
                {
                    genomeModel.OverallStatus = customErrorMsg;
                }
            }

            else
            {
                genomeModel.OverallStatus = GetOverallStepList()[++genomeModel.OverallCurrentStep].ToString();
            }
        }
 public void SetupLoadAsyncToReturn(Expression <Func <string, bool> > match, GenomeModel returnValue)
 {
     _mock.Setup(x => x.LoadAsync(It.Is(match))).Returns(Task.FromResult(returnValue));
 }
Exemple #11
0
 /// <param name="genomeModel">The model data of the current job.</param>
 /// <param name="dataSources">A stored list of strings containing the location(s) of the user's data set.</param>
 /// <param name="seed">Seed value for a unique name for the job.</param>
 public JobBuilder(GenomeModel genomeModel, List <string> dataSources, int seed)
 {
     this.genomeModel = genomeModel;
     this.seed        = seed;
     this.dataSources = dataSources;
 }
        public ActionResult Create(GenomeModel genomeModel)
        {
            if (ModelState.IsValid)
            {
                // TODO: Consider the JELLYFISH SIZE. Rec size is est_genome_size  * estimated coverage. (This should be done in Javascript).
                // Should that be a field that we include in the model so we can calculate a safe size or just
                // have them do it? I think just have them do it with a tooltip and make it a required field.
                try
                {
                    #region Set General Information

                    HelperMethods.SetDefaultMasurcaValues(genomeModel);

                    genomeModel.OverallCurrentStep = 1;
                    genomeModel.OverallStatus      = StepDescriptions.INITIAL_STEP;
                    genomeModel.NumberOfAssemblers = HelperMethods.NumberOfAssemblers(genomeModel.UseMasurca, genomeModel.UseSGA, genomeModel.UseWGS);

                    // TODO: Potentially add the model to the DB now with junk data to reserve the UUID so we don't have to use a SEED value at all. This
                    // reduces the potential of something going wrong and two people ending up with a race condition or something.

                    genomeModel.CreatedBy = User.Identity.Name;

                    // TODO: Need to look into this to see about a translation to display to a user rather than the UK time it gives.
                    genomeModel.CreatedDate = DateTime.UtcNow;

                    #endregion

                    #region Create Scripts

                    List <string> dataSources = HelperMethods.ParseUrlString(genomeModel.DataSource);

                    Random rand = new Random();
                    int    seed = rand.Next(198, 1248712);

                    JobBuilder builder = new JobBuilder(genomeModel, dataSources, seed);
                    builder.GenerateConfigs();

                    genomeModel.Seed = builder.seed; // Set seed value here so we know it is 100% definitely set.
                    #endregion

                    #region Connect To BigDog and Test Data Connection

                    string badUrl = HelperMethods.TestJobUrls(genomeModel.SSHUser, genomeModel.SSHPass, genomeModel.DataSource);

                    if (string.IsNullOrEmpty(badUrl) && string.IsNullOrEmpty(ErrorHandling.error))
                    {
                        /// We can instead pass in the SEED variable which will be used to reference the method in Locations to grab the correct file(s).
                        /// This is the ideal solution which will be implemented only once we know that the system works with the direct URL.
                        builder.CreateJob();

                        // No error so proceed.
                        if (ErrorHandling.NoError())
                        {
                            db.GenomeModels.Add(genomeModel);
                            db.SaveChanges();

                            return(RedirectToAction("Details", new { id = genomeModel.uuid }));
                        }

                        // Redisplay the data and display the error.
                        else
                        {
                            genomeModel.JobError = "We encountered an error while trying to submit your job. The following is the error we encountered: " + ErrorHandling.error;

                            return(View(genomeModel));
                        }
                    }

                    // Redisplay the data and display the error.
                    else
                    {
                        genomeModel.JobError = "There was an error with the URLs provided. We weren't able to locate or download at least"
                                               + " one of your files. The file we had a problem with was: " + badUrl + ". Please make sure you typed the URL correctly"
                                               + " and it is accessible. If this is in error, please contact an administrator promptly with the details.";

                        if (!string.IsNullOrEmpty(ErrorHandling.error))
                        {
                            genomeModel.JobError = string.Concat(genomeModel.JobError, " The following is additional error information that we encountered: " + ErrorHandling.error);
                        }

                        return(View(genomeModel));
                    }

                    #endregion
                }

                catch (Exception e)
                {
                    genomeModel.JobError = "There has been an uncaught error. " + e;
                }
            }

            return(View(genomeModel));
        }
        /// <summary>
        /// Updates the status of a single job. But it does not perform the upload if that needs to happen.
        /// </summary>
        /// <param name="genomeModel">The model of the particular job.</param>
        protected internal static void UpdateStatus(GenomeModel genomeModel)
        {
            using (var client = new SshClient(CreatePrivateKeyConnectionInfo()))
            {
                try
                {
                    client.Connect();

                    /// TODO: Modify the code to skip entire sections if they have already been completed. This will be based off the CURRENT STEP stored in the model data.
                    using (GenomeAssemblyDbContext db = new GenomeAssemblyDbContext())
                    {
                        bool continueUpdate = true;     // Determines whether we will continue checking the job status.
                        bool DEBUG_MODE     = false;    // Debug mode to skip some assembler steps.
                        bool outOfRange     = false;    // If the overall step is out of bounds, then we set this to true to attempt a correction.
                        ErrorHandling.error = "";       // Reset the errror flag.

                        while (continueUpdate && ErrorHandling.NoError())
                        {
                            // Depending on the current step, this switch will determine if the state of the job needs to change.
                            switch (genomeModel.OverallCurrentStep)
                            {
                            // Queued step
                            case 1:
                            {
                                if (DEBUG_MODE)
                                {
                                    genomeModel.NextStep();
                                    break;
                                }

                                if (LinuxCommands.IsProcessRunning(client, "conversionScript.sh"))
                                {
                                    genomeModel.NextStep();
                                }

                                // If a conversion was never run or if we missed it, then check if the job has already started.
                                else if (LinuxCommands.JobRunningAlt(client, genomeModel.SSHUser))
                                {
                                    genomeModel.NextStep();
                                }

                                else
                                {
                                    continueUpdate = false;
                                }

                                break;
                            }

                            // Data conversion step
                            case 2:
                            {
                                if (DEBUG_MODE)
                                {
                                    genomeModel.NextStep();
                                    break;
                                }

                                if (LinuxCommands.DirectoryHasFiles(client, Accessors.GetMasurcaOutputPath(genomeModel.Seed)))
                                {
                                    genomeModel.NextStep();
                                }

                                else
                                {
                                    continueUpdate = false;
                                }

                                break;
                            }

                            // Running assemblers step
                            case 3:
                            {
                                if (DEBUG_MODE)
                                {
                                    genomeModel.NextStep();
                                    break;
                                }

                                if (genomeModel.UseMasurca)
                                {
                                    CheckMasurcaStep(client, genomeModel);
                                }

                                if (genomeModel.UseSGA)
                                {
                                }

                                if (genomeModel.UseWGS)
                                {
                                }

                                if (genomeModel.IsAssemblyFinished())
                                {
                                    genomeModel.NextStep();
                                }

                                else
                                {
                                    continueUpdate = false;
                                }

                                break;
                            }

                            // Data analysis step
                            case 4:
                            {
                                // Until data analysis is implemented, we skip the step.
                                genomeModel.NextStep();
                                break;

                                //if (LinuxCommands.IsProcessRunning(client, "dataAnalysis.sh"))
                                //    continueUpdate = false;

                                //else
                                //{
                                //    // Has it finished?
                                //    if (LinuxCommands.FileExists(client, Accessors.GetJobOutputPath(genomeModel.Seed) + "dataAnalysisResult"))
                                //        genomeModel.NextStep();

                                //    else
                                //        LinuxCommands.RunDataAnalysis(client);
                                //}

                                //break;
                            }

                            // TODO: Create a more robust method in checking for a completed upload. Maybe connect to the FTP and compare file sizes and see if they are close.
                            // Uploading Data step
                            case 5:
                            {
                                //if (LinuxCommands.IsJobUploading(client, Accessors.USER_ROOT_JOB_DIRECTORY, Accessors.GetCompressedDataPath(genomeModel.Seed)))
                                //    continueUpdate = false;

                                //else if (LinuxCommands.FileExists(client, Accessors.GetCompressedDataPath(genomeModel.Seed)))
                                //    genomeModel.NextStep();

                                //else
                                //{
                                LinuxCommands.UploadJobData(client, Accessors.USER_ROOT_JOB_DIRECTORY, Accessors.GetCompressedDataPath(genomeModel.Seed)
                                                            , Accessors.GetRelativeJobDirectory(genomeModel.Seed), Accessors.GetRemoteDownloadLocation(genomeModel.Seed), true, "yr");

                                continueUpdate = false;
                                //}


                                break;
                            }

                            // Completed step
                            case 6:
                            {
                                continueUpdate = false;

                                break;
                            }

                            default:
                            {
                                // If we have attempted a correction and failed, throw in the towel.
                                if (outOfRange)
                                {
                                    throw new IndexOutOfRangeException("The current step of the program is out of bounds after an attempted correction. The current step: "
                                                                       + genomeModel.OverallCurrentStep);
                                }

                                else
                                {
                                    outOfRange = true;

                                    // Reset the state to default and have it run through the update method again.
                                    genomeModel.OverallCurrentStep = 1;
                                    genomeModel.OverallStatus      = StepDescriptions.GetOverallStepList()[genomeModel.OverallCurrentStep].ToString();
                                }

                                break;
                            }
                            }
                        }
                    }
                }

                // SSH Connection couldn't be established.
                catch (SocketException e)
                {
                    ErrorHandling.error = "The SSH connection couldn't be established. " + e.Message;
                }

                // The SSH connection was dropped.
                catch (SshConnectionException e)
                {
                    ErrorHandling.error = "The connection was terminated unexpectedly. " + e.Message;
                }
            }
        }
Exemple #14
0
 /// <inheritdoc/>
 public Task<GenomeModel> LoadAsync(string path)
 {
     return Task.Run(() => GenomeModel.Load(path));
 }
Exemple #15
0
 public static void SetMasurcaError(SshClient client, GenomeModel genomeModel)
 {
     genomeModel.MasurcaCurrentStep = -1;
     genomeModel.MasurcaStatus      = LinuxCommands.GetMasurcaError(client, genomeModel.Seed);
 }