public FaToolDbControllerBase() { faToolDbEntities = new FaToolDbEntities(); faToolDbEntities.Configuration.AutoDetectChangesEnabled = false; faToolDbEntities.Configuration.LazyLoadingEnabled = false; faToolDbEntities.Configuration.ProxyCreationEnabled = true; }
public async Task <ActionResult> SetTerm( [Bind(Prefix = "Args")] AnnotationEditArgs editArgs) { if (!ModelState.IsValid) { return(HttpStatusCodeResults.HttpBadRequest(ModelState)); } var annotation = Restore <Annotation>("Entity", true); var termQuery = new TermQuery(); TryUpdateModel(termQuery, "TermQuery"); ModelState.Clear(); if (string.IsNullOrWhiteSpace(editArgs.SelectedTermId) == false) { if (await FaToolDbEntities.Exists <Annotation>(x => x.FK_Protein == annotation.FK_Protein && x.FK_Term == editArgs.SelectedTermId)) { ModelState.AddModelError("Args.SelectedTermId", "Selected function term already mapped to protein."); return(await SelectTerm(annotation, termQuery, editArgs)); } else { annotation.FK_Term = editArgs.SelectedTermId; } } else { ModelState.AddModelError("Args.SelectedTermId", "A term must be selected."); return(await SelectTerm(annotation, termQuery, editArgs)); } return(await Edit(annotation, editArgs)); }
public async Task <ActionResult> GetOntologies() { var options = await FaToolDbEntities.GetOntologyOptions(null); var ontologies = options.Select(x => new { id = x.Value, name = x.Text }).ToArray(); return(Json(ontologies, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> GetSourceOrganisms() { var options = await FaToolDbEntities.GetSourceOrganismOptions(null); var orgs = options.Select(x => new { id = x.Value, name = x.Text }).ToArray(); return(Json(orgs, JsonRequestBehavior.AllowGet)); }
private async Task <FunctionSearchViewModel> CreateFunctionSearch() { var query = new ProteinSearchQuery(); var sourceOrganisms = await FaToolDbEntities.GetSourceOrganismOptions(query.SourceOrganismID); query.SearchOption = ProteinSearchOption.Function; query.SourceOrganismID = sourceOrganisms.FirstOrDefault().Value; var model = new FunctionSearchViewModel(query, sourceOrganisms); return(model); }
private async Task <ActionResult> Edit(Annotation annotation, AnnotationEditArgs editArgs) { ViewBag.Title = "Edit Annotation"; var model = new AnnotationEditViewModel(); model.Args = editArgs; model.Entity = annotation; model.GoEvidenceOptions = EnumSources.GetGoEvidenceOptions(annotation.EvidenceCode); model.TermOptions = await FaToolDbEntities.GetSelectedTerm(annotation.FK_Term); return(View("Edit", model)); }
private async Task <ActionResult> ChangeTerm(Annotation annotation, TermQuery termQuery, AnnotationEditArgs editArgs) { ViewBag.Title = "Change Term"; var model = new AnnotationEditViewModel(); model.Args = editArgs; model.Entity = annotation; model.TermQuery = termQuery; model.OntologyOptions = await FaToolDbEntities.GetOntologyOptions(model.TermQuery.OntologyId); return(View("ChangeTerm", model)); }
public async Task <ActionResult> Create(Guid proteinId) { var annotation = FaToolDbEntities.Init <Annotation, Guid?>(Guid.NewGuid()); annotation.FK_Protein = proteinId; annotation.EntryDate = DateTimeOffset.Now; annotation.EvidenceCode = GOEvidences.Default.Code; var editArgs = new AnnotationEditArgs(); editArgs.SaveAction = Url.Action("Insert"); editArgs.EndEditAction = Url.EntityGetAction("Proteins", proteinId, ProteinNavId.Functions); return(await Edit(annotation, editArgs)); }
public static async Task <IEnumerable <SelectListItem> > GetSourceOrganismOptions( this FaToolDbEntities entities, string selected) { var query = from gms in entities.GeneModelSources.AsNoTracking() select new SelectListItem() { Value = gms.Organism.ID, Text = gms.Organism.Name, Selected = gms.Organism.ID == selected }; var orgs = await query.Distinct().OrderBy(x => x.Text).ToArrayAsync(); return(orgs); }
public async Task <ActionResult> Get(Guid id, AnnotationNavId navId = AnnotationNavId.Term) { var annotation = await FaToolDbEntities.Find <Annotation>(id); if (annotation == null) { return(HttpNotFound("Entity not found in database.")); } await FaToolDbEntities.LoadReference(annotation, x => x.Term, "Ontology"); ViewBag.Title = string.Format("Annotation '{0}' - [{1}]", annotation.Term.Name, navId.ToString()); var model = new EntityView <Annotation, AnnotationNavId>(); model.NavTabs = Url.CreateNavTabs <Guid?, AnnotationNavId>(id); model.ActiveTab = model.NavTabs.ToggleActive(navId); model.Properties = new AnnotationRecordView(annotation); model.Properties.Actions.Add(Url.EntityActionLink("Edit", "Edit", id, User.IsAdminRole() == false)); model.Properties.Actions.Add(Url.EntityGetActionLink("Back to Protein", "Proteins", annotation.FK_Protein, ProteinNavId.Functions)); switch (navId) { case AnnotationNavId.Term: await FaToolDbEntities.LoadReference(annotation, x => x.Term, "Ontology"); model.TabContent = new TermRecordView(annotation.Term); break; case AnnotationNavId.References: await FaToolDbEntities.LoadCollection(annotation, x => x.References); model.TabContent = new ParamList(annotation.Params); break; case AnnotationNavId.Description: await FaToolDbEntities.LoadCollection(annotation, x => x.Params, "Term.Ontology", "Unit.Ontology"); model.TabContent = new PubReferenceList(annotation.References); break; default: break; } return(View("EntityDefault", model)); }
private async Task <ProteinSearchViewModel> CreateModel(ProteinSearchQuery psq, int pageIndex) { var model = new ProteinSearchViewModel(); model.Query = psq; model.SourceOrganisms = await FaToolDbEntities.GetSourceOrganismOptions(psq.SourceOrganismID); model.SearchOptions = EnumSources.GetProteinSearchOptions(psq.SearchOption); model.StatusDescription = string.Empty; model.Results = Enumerable.Empty <ProteinSearchResult>(); model.ResultsAction = Url.Action("Results", new { pageIndex = 0 }); model.NextResultsAction = Url.Action("Results", new { pageIndex = pageIndex + 1 }); model.PreviousResultsAction = Url.Action("Results", new { pageIndex = pageIndex - 1 }); return(model); }
public static async Task <IEnumerable <SelectListItem> > GetOntologyOptions( this FaToolDbEntities entities, string selected) { return(await entities .Ontologies .AsNoTracking() .OrderBy(x => x.Name) .Select(x => new SelectListItem() { Text = x.Name, Value = x.ID, Selected = x.ID == selected }) .ToArrayAsync()); }
public async Task <ActionResult> Edit(Guid id) { var annotation = await FaToolDbEntities.Find <Annotation>(id); if (annotation == null) { return(HttpNotFound("Entity not found in database.")); } var editArgs = new AnnotationEditArgs(); editArgs.SaveAction = Url.Action("Update"); editArgs.EndEditAction = Url.EntityGetAction(annotation.ID); return(await Edit(annotation, editArgs)); }
public static async Task <IEnumerable <SelectListItem> > GetTermOptions( this FaToolDbEntities entities, TermQuery query, string selected) { return(await entities .Terms .AsNoTracking() .Where(x => x.Name.Contains(query.SearchValue) && x.FK_Ontology == query.OntologyId) .OrderBy(x => x.Name) .Select(x => new SelectListItem() { Value = x.ID, Text = x.Name, Selected = x.ID == selected }) .ToArrayAsync()); }
public async Task <ActionResult> SearchFunctions(FunctionSearchQuery fsq) { if (ModelState.IsValid) { var query = from sp in FaToolDbEntities.GetProteinSearchValues(ProteinSearchOption.ProteinName, fsq.OrganismId) join fp in FaToolDbEntities.GetProteinSearchValues(ProteinSearchOption.Function, fsq.OrganismId) on sp.ProteinID equals fp.ProteinID where sp.Value == fsq.SearchName && fp.OntologyID == fsq.OntologyId select new { id = fp.TermID, name = fp.TermName }; var results = await query.ToArrayAsync(); return(Json(results, JsonRequestBehavior.AllowGet)); } else { return(HttpStatusCodeResults.HttpBadRequest(ModelState)); } }
public static async Task <IEnumerable <SelectListItem> > GetSelectedTerm( this FaToolDbEntities entities, string termId) { if (string.IsNullOrWhiteSpace(termId)) { return(Enumerable.Empty <SelectListItem>()); } return(await entities .Terms .AsNoTracking() .Where(x => x.ID == termId) .Select(x => new SelectListItem() { Value = x.ID, Text = x.Name, Selected = true }) .ToArrayAsync()); }
private async Task <ActionResult> SelectTerm(Annotation annotation, TermQuery termQuery, AnnotationEditArgs editArgs) { ViewBag.Title = "Select Term"; var model = new AnnotationEditViewModel(); model.Args = editArgs; model.Entity = annotation; model.TermQuery = termQuery; model.OntologyOptions = await FaToolDbEntities.GetOntologyOptions(model.TermQuery.OntologyId); model.TermOptions = await FaToolDbEntities.GetTermOptions(termQuery, annotation.FK_Term); if (model.TermOptions.Any()) { return(View("SelectTerm", model)); } else { ModelState.AddModelError("TermQuery.SearchValue", "No Terms found."); return(View("ChangeTerm", model)); } }
private async Task <ProteinSearchViewModel> Search(ProteinSearchQuery psq, int pageIndex) { var model = await CreateModel(psq, pageIndex); var query = FaToolDbEntities .GetProteinSearchValues(psq.SearchOption, psq.SourceOrganismID) .Where(pv => pv.Value.Contains(psq.SearchValue)); int numResults = await query.CountAsync(); if (numResults == 0) { model.StatusDescription = "Query does not return any results."; } else { int numPages = DataPaging.CalculatePageCount(numResults); pageIndex = DataPaging.FixPageIndex(numPages, pageIndex); int skip = DataPaging.CalculateSkipCount(numResults, pageIndex); var proteinValues = await query .OrderBy(x => x.Value) .ThenBy(x => x.TermName) .ThenBy(x => x.ProteinName) .Skip(skip) .Take(DataPaging.PageSize) .ToArrayAsync(); model.Results = proteinValues .Select(CreateItem) .ToArray(); model.StatusDescription = CreateDescription(numResults, numPages, pageIndex); } return(model); }
public async Task <ActionResult> Get(Guid id, ProteinNavId navId = ProteinNavId.Functions) { var protein = await FaToolDbEntities.Find <Protein>(id); if (protein == null) { return(HttpNotFound("Protein not found in database.")); } ViewBag.Title = string.Format("Protein '{0}' - [{1}]", protein.Name, navId.ToString()); var model = new EntityView <Protein, ProteinNavId>(); model.NavTabs = Url.CreateNavTabs <Guid?, ProteinNavId>(id); model.ActiveTab = model.NavTabs.ToggleActive(navId); model.Properties = new ProteinRecordView(protein); switch (navId) { case ProteinNavId.Functions: await FaToolDbEntities.LoadCollection(protein, x => x.Annotations, "Term.Ontology"); var annotationList = new AnnotationList(protein.Annotations); annotationList.AddRowAction(x => Url.EntityGetActionLink("Show", "Annotations", x.ID)); annotationList.Actions.Add(Url.ActionLink("Add", "Create", "Annotations", new { proteinId = id }, User.IsAdminRole() == false)); model.TabContent = annotationList; break; case ProteinNavId.Synonyms: await FaToolDbEntities.LoadCollection(protein, x => x.Synonyms, "SynonymType.Ontology"); model.TabContent = new SynonymList(protein.Synonyms); break; case ProteinNavId.Description: await FaToolDbEntities.LoadCollection(protein, x => x.Params, "Term.Ontology", "Unit.Ontology"); model.TabContent = new ParamList(protein.Params); break; case ProteinNavId.References: await FaToolDbEntities.LoadCollection(protein, x => x.References); model.TabContent = new PubReferenceList(protein.References); break; case ProteinNavId.GeneModels: await FaToolDbEntities.LoadCollection(protein, x => x.GeneModels, "GeneModelSource.Organism.Ontology"); model.TabContent = new GeneModelList(protein.GeneModels); break; case ProteinNavId.Homologs: await FaToolDbEntities.LoadCollection(protein, x => x.ProteinHomologyGroups, "Group"); model.TabContent = new ProteinHomologyGroupList(protein.ProteinHomologyGroups); break; default: throw new InvalidOperationException("Invalid nav id."); } return(View("EntityDefault", model)); }