Example #1
0
        public ActionResult AddTreePicture(FormCollection col, TreeModel model)
        {
            if (Request.Files.Count > 0)
            {
                var file = Request.Files[0];

                if (file != null && file.ContentLength > 0)
                {
                    string fileName = Path.GetFileName(file.FileName);

                    var path = Path.Combine(Server.MapPath("~/ServiceResults/Trees/"), fileName);
                    file.SaveAs(path);
                    ObjectId        projId  = ObjectId.Parse(model.ProjectId);
                    SequenceProject project = db.GetItem <SequenceProject>(x => x._id == projId);
                    if (project != null && model.AlignmentId != String.Empty)
                    {
                        AlignmentSequence alignment = project.Alligments.First(x => x.IdString == model.AlignmentId);
                        if (alignment != null)
                        {
                            alignment.TreePicture = path;
                            db.UpdateItem(project);
                        }
                    }
                }
            }
            return(RedirectToAction("ViewTree", new { projectId = model.ProjectId, alignmentId = model.AlignmentId }));
        }
Example #2
0
        public ActionResult ViewTree(string projectId, string alignmentId)
        {
            ObjectId        projId  = ObjectId.Parse(projectId);
            SequenceProject project = db.GetItem <SequenceProject>(x => x._id == projId);

            if (project != null && alignmentId != String.Empty)
            {
                AlignmentSequence alignment = project.Alligments.First(x => x.IdString == alignmentId);
                if (alignment != null && !String.IsNullOrEmpty(alignment.PhylogeneticTree))
                {
                    string fileContent = String.Empty;
                    if (System.IO.File.Exists(alignment.TreePicture))
                    {
                        using (StreamReader sr = new StreamReader(alignment.TreePicture))
                        {
                            fileContent = sr.ReadToEnd();
                        }
                    }
                    return(View("ViewTree", new TreeModel()
                    {
                        TreeString = alignment.PhylogeneticTree, AlignmentName = alignment.Description, ProjectId = projectId, AlignmentId = alignmentId, TreeFile = fileContent
                    }));
                }
            }
            return(View());
        }
        public ActionResult ViewAlignment(string projectId, string alignmentId)
        {
            ObjectId        projId  = ObjectId.Parse(projectId);
            SequenceProject project = db.GetItem <SequenceProject>(x => x._id == projId);

            if (project != null && alignmentId != String.Empty)
            {
                AlignmentSequence alignment = project.Alligments.First(x => x.IdString == alignmentId);
                if (alignment != null && alignment.AllignedSequences != null && alignment.AllignedSequences.Any())
                {
                    return(View("ViewAlignmentRaw", new AlignmentModel()
                    {
                        AlignmentSequences = alignment.AllignedSequences, AlignmentName = alignment.Description, AlignmentId = alignmentId, ProjectId = projectId
                    }));
                }
            }
            return(View(new HtmlString("")));
        }
        public bool GetSimplePhyloResult(SequenceProject project, string alignmentId)
        {
            IList <string> records = new List <string>();

            if (project != null && project.Alligments != null)
            {
                AlignmentSequence alignment = project.Alligments.First(x => x._id == ObjectId.Parse(alignmentId));
                string            result    = alignment.PhylogeneticFilename + ".tree.ph";
                if (alignment != null)
                {
                    if (!File.Exists(result))
                    {
                        result = phylologyService.GetResults(alignment.PhylogeneticGuid, alignment.PhylogeneticFilename);
                        if (String.IsNullOrEmpty(result))
                        {
                            return(false);
                        }
                        result = result + ".tree.ph";
                    }
                    if (!String.IsNullOrEmpty(result))
                    {
                        using (StreamReader sr = new StreamReader(result))
                        {
                            StringBuilder sb = new StringBuilder();
                            while (!sr.EndOfStream)
                            {
                                string hlpString = sr.ReadLine();
                                sb.AppendLine(hlpString);
                                records.Add(hlpString);
                            }
                            foreach (string s in records)
                            {
                                alignment.PhylogeneticTree += s;
                            }
                            db.UpdateItem(project);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        public bool GetClustalResult(SequenceProject project, string alignmentId)
        {
            IList <string> records = new List <string>();

            if (project != null && project.Alligments != null)
            {
                AlignmentSequence alignment = project.Alligments.First(x => x._id == ObjectId.Parse(alignmentId));
                string            result    = alignment.AlignmentFilename + ".vienna.aln-vienna.vienna";
                if (alignment != null)
                {
                    if (!File.Exists(result))
                    {
                        result = clustalService.GetResults(alignment.AlignmentGuid, alignment.AlignmentFilename);
                        if (String.IsNullOrEmpty(result))
                        {
                            return(false);
                        }
                        result = result + ".aln-vienna.vienna";
                    }
                    if (!String.IsNullOrEmpty(result))
                    {
                        using (StreamReader sr = new StreamReader(result))
                        {
                            StringBuilder sb = new StringBuilder();
                            while (!sr.EndOfStream)
                            {
                                string hlpString = sr.ReadLine();
                                sb.AppendLine(hlpString);
                                records.Add(hlpString);
                            }
                            alignment.AllignedSequences = GetRecordsFromResult(project._id, records);
                            alignment.IsFinished        = true;
                            db.UpdateItem(project);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        /// <summary>
        /// Založení sekvenčního zarovnání v programu ClustalOmega
        /// </summary>
        /// <param name="projectId"></param>
        public void GenerateClustalAligment(ObjectId projectId, string title, string path)
        {
            IList <Sequence> sequences = db.GetCollection <Sequence>(x => x.ProjectId == projectId && x.Selected == true && String.IsNullOrEmpty(x.BlastAlignedSequence));
            string           seq       = String.Empty;

            foreach (Sequence s in sequences)
            {
                seq += s.FastaProtein;
            }
            clustalService.SetParams(new ServiceConnector.ClustalConnector.InputParameters()
            {
                sequence = seq, outfmt = "vienna"
            });
            var project = db.GetItem <SequenceProject>(x => x._id == projectId);

            if (project != null)
            {
                if (project.Alligments == null)
                {
                    project.Alligments = new List <AlignmentSequence>();
                }
                AlignmentSequence allign = new AlignmentSequence()
                {
                    Created     = DateTime.Now,
                    CreatorId   = project.CreatorId,
                    Description = title,
                    IsFinished  = false,
                    _id         = ObjectId.GenerateNewId(),
                    Source      = "Cazy"
                };
                allign.AlignmentGuid     = clustalService.Run(title);
                allign.Taxons            = project.ActualTaxons;
                allign.AlignmentFilename = path + allign.AlignmentGuid;
                project.Alligments.Add(allign);
                db.UpdateItem(project);
                SelUnSelAllSequence(project.IdString, false, false);
            }
        }
        public void GenerateTree(ObjectId projectId, string alignmentId, string path)
        {
            SequenceProject project = db.GetItem <SequenceProject>(x => x._id == projectId);

            if (project != null)
            {
                AlignmentSequence aligment = project.Alligments.FirstOrDefault(x => x.IdString == alignmentId);
                if (aligment != null)
                {
                    string seq = String.Empty;
                    foreach (AlignRecord rec in aligment.AllignedSequences)
                    {
                        seq += ">" + rec.Organism.Replace(" ", "_") + "\n" + rec.AlignedSequence + "\n";
                    }
                    phylologyService.SetParams(new ServiceConnector.PhylogenyConnector.InputParameters()
                    {
                        sequence = seq, tree = "phylip"
                    });
                    aligment.PhylogeneticGuid     = phylologyService.Run(aligment.Description);
                    aligment.PhylogeneticFilename = path + aligment.PhylogeneticGuid;
                    db.UpdateItem(project);
                }
            }
        }
 public bool GetBlastSearchResult(SequenceProject project, string path, UserProject userProject)
 {
     if (project != null)
     {
         //XmlResult
         string result = path + project.BlastSearchGuid + ".xml.xml";
         if (!File.Exists(result))
         {
             result = blastService.GetResults(project.BlastSearchGuid, result);
             if (String.IsNullOrEmpty(result))
             {
                 return(false);
             }
         }
         if (!String.IsNullOrEmpty(result))
         {
             using (StreamReader sr = new StreamReader(result))
             {
                 StringBuilder        sb        = new StringBuilder();
                 XmlReader            reader    = XmlReader.Create(sr);
                 EBIApplicationResult ebiResult = GenerateSequencesFromXml(reader);
                 if (ebiResult != null && ebiResult.SequenceSimilaritySearchResult != null)
                 {
                     IList <Sequence> sequencies = CreateBlastSequencies(ebiResult.SequenceSimilaritySearchResult.hits, project, userProject);
                     if (project.Alligments == null)
                     {
                         project.Alligments = new List <AlignmentSequence>();
                     }
                     if (sequencies != null && sequencies.Any())
                     {
                         AlignmentSequence allign = new AlignmentSequence()
                         {
                             Created           = DateTime.Now,
                             CreatorId         = project.CreatorId,
                             Description       = "BlastAlignment",
                             IsFinished        = false,
                             _id               = ObjectId.GenerateNewId(),
                             Source            = "Blast",
                             AllignedSequences = new List <AlignRecord>()
                         };
                         foreach (Sequence seq in sequencies)
                         {
                             allign.AllignedSequences.Add(new AlignRecord()
                             {
                                 AlignedSequence = seq.BlastAlignedSequence,
                                 Organism        = seq.Organism,
                                 SequenceId      = seq._id,
                                 SequenceName    = seq.Name,
                                 SequenceHeader  = seq.Description
                             });
                         }
                         project.Alligments.Add(allign);
                         db.UpdateItem(project);
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }