Skip to content

Commit

Permalink
Add Spawn API endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Mar 12, 2021
1 parent 9cad63e commit 89aa7bc
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .assets/assets/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
<Id>5d6f5462-3401-48ec-9406-d12882e9ad83</Id>
<Version>0.4.5</Version>
<Version>0.4.6</Version>
<ProviderName>Computational Systems Biology</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="Swate"/>
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 0.4.6+9cad63e (Released 2021-3-12)
* Additions:
* latest commit #9cad63e
* [[#9cad63e](https://github.com/nfdi4plants/Swate/commit/9cad63e1cd456b377fe42ce1d5488412eacf19db)] Merge pull request #141 from nfdi4plants/kevinf-patch-0.4.5

### 0.4.5+b360273 (Released 2021-3-12)
* Additions:
* latest commit #b360273
Expand Down
2 changes: 1 addition & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
<Id>5d6f5462-3401-48ec-9406-d12882e9ad83</Id>
<Version>0.4.5</Version>
<Version>0.4.6</Version>
<ProviderName>Computational Systems Biology</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="Swate"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Messages.fs
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ type Model = {

and Msg =
| Bounce of (System.TimeSpan*string*Msg)
| DebouncerSelfMsg of Debouncer.SelfMessage<Msg>
| Api of ApiMsg
| Dev of DevMsg
| TermSearch of TermSearchMsg
| AdvancedSearch of AdvancedSearchMsg
| DebouncerSelfMsg of Debouncer.SelfMessage<Msg>
| ExcelInterop of ExcelInteropMsg
| StyleChange of StyleChangeMsg
| PersistentStorage of PersistentStorageMsg
Expand Down
5 changes: 5 additions & 0 deletions src/Client/Model.fs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ type AdvancedTermSearchOptions = {
}

type TermSearchState = {

TermSearchText : string

SelectedTerm : DbDomain.Term option
TermSuggestions : DbDomain.Term []

ParentOntology : OntologyInfo option
SearchByParentOntology : bool

HasSuggestionsLoading : bool
ShowSuggestions : bool

} with
static member init () = {
TermSearchText = ""
Expand Down
51 changes: 49 additions & 2 deletions src/Server/Docs/DocsAnnotationAPIvs1.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,68 @@ let annotatorApiDocsv1 =

////////
annotatorDocsv1.route <@ fun api -> api.getTermSuggestionsByParentTerm @>
|> annotatorDocsv1.alias "Get Terms By Parent Ontology (<code>getTermSuggestionsByParentTerm</code>)"
|> annotatorDocsv1.alias "Get Terms By Parent Ontology Term (<code>getTermSuggestionsByParentTerm</code>)"
|> annotatorDocsv1.description (
createDocumentationDescription
"This is a <code>getTermSuggestions</code> variant, used to reduce the number of possible hits searching only data that is in a \"is_a\" relation to the parent ontology (written at the top of the column)."
"If a column with a parent ontology is selected, the app will add this to the 'TermSearch' field in a static button. This can be toggled but a small slider below. If this alternative term search is active then <code>getTermSuggestionsByParentTerm</code> is executed."
(Some [|
Parameter.create "n" ParamInteger "This parameter sets the number of returned results."
Parameter.create "queryString" ParamString "This parameter is used to search the Term.Name column for hits."
Parameter.create "parentOntology" ParamString "This parameter is used to search <b>only</b> is_a relationships by the parentOntology (Term.Name)."
Parameter.create "parentOntology" DocsFunctions.PredefinedParams.OntologyInfoType "This parameter is used to search <b>only</b> is_a relationships by the parentOntology (Term.Name, Term.Accession)."
|])
"This function returns an array of matching Database.Term entries in the form of <code>DbDomain.Term []</code>."
(Parameter.create "Term []" (PredefinedParams.TermType |> ParamArray) "Array of database Term entries.")
)
|> annotatorDocsv1.example <@ fun api -> api.getTermSuggestionsByParentTerm (5,"micrOTOF-Q",PredefinedParams.Examples.ontologyInfoExmp) @>

////////
annotatorDocsv1.route <@ fun api -> api.getAllTermsByParentTerm @>
|> annotatorDocsv1.alias "Get All Terms By Parent Ontology Term (<code>getAllTermsByParentTerm</code>)"
|> annotatorDocsv1.description (
createDocumentationDescription
"This is a <code>getTermSuggestions</code> variant, used to reduce the number of possible hits searching only data that is in a \"is_a\" relation to the parent ontology (written at the top of the column)."
"If a column with a parent ontology is selected, the app will add this to the 'TermSearch' field in a static button. This can be toggled but a small slider below. If this alternative term search is active then <code>getAllTermsByParentTerm</code> and the input field is still empty, a double click will trigger this search."
(Some [|
Parameter.create "parentOntology" DocsFunctions.PredefinedParams.OntologyInfoType "This parameter is used to search <b>only</b> is_a relationships by the parentOntology (Term.Name, Term.Accession)."
|])
"This function returns an array of matching Database.Term entries in the form of <code>DbDomain.Term []</code>."
(Parameter.create "Term []" (PredefinedParams.TermType |> ParamArray) "Array of database Term entries.")
)
|> annotatorDocsv1.example <@ fun api -> api.getAllTermsByParentTerm PredefinedParams.Examples.ontologyInfoExmp @>

////////
annotatorDocsv1.route <@ fun api -> api.getTermSuggestionsByChildTerm @>
|> annotatorDocsv1.alias "Get Terms By Child Ontology Term (<code>getTermSuggestionsByChildTerm</code>)"
|> annotatorDocsv1.description (
createDocumentationDescription
"This function does something similiar to <code>getTermSuggestionsByParentTerm</code>. But instead of searching children in a is_a directed search, it searches all parents in a is_a directed search."
"It is used purely as API endpoint for Spawn, but might be implemented for Swate in the future."
(Some [|
Parameter.create "n" ParamInteger "This parameter sets the number of returned results."
Parameter.create "queryString" ParamString "This parameter is used to search the Term.Name column for hits."
Parameter.create "parentOntology" DocsFunctions.PredefinedParams.OntologyInfoType "This parameter is used to search <b>only</b> is_a relationships by the parentOntology (Term.Name, Term.Accession)."
|])
"This function returns an array of matching Database.Term entries in the form of <code>DbDomain.Term []</code>."
(Parameter.create "Term []" (PredefinedParams.TermType |> ParamArray) "Array of database Term entries.")
)
|> annotatorDocsv1.example <@ fun api -> api.getTermSuggestionsByChildTerm (5,"inst",PredefinedParams.Examples.ontologyInfoExmp2) @>

////////
annotatorDocsv1.route <@ fun api -> api.getAllTermsByChildTerm @>
|> annotatorDocsv1.alias "Get All Terms By Child Ontology Term (<code>getAllTermsByChildTerm</code>)"
|> annotatorDocsv1.description (
createDocumentationDescription
"This is a <code>getTermSuggestions</code> variant, used to reduce the number of possible hits searching only data that is in a \"is_a\" relation to the child ontology term."
"It is used purely as API endpoint for Spawn, but might be implemented for Swate in the future."
(Some [|
Parameter.create "parentOntology" DocsFunctions.PredefinedParams.OntologyInfoType "This parameter is used to search <b>only</b> is_a relationships by the parentOntology (Term.Name, Term.Accession)."
|])
"This function returns an array of matching Database.Term entries in the form of <code>DbDomain.Term []</code>."
(Parameter.create "Term []" (PredefinedParams.TermType |> ParamArray) "Array of database Term entries.")
)
|> annotatorDocsv1.example <@ fun api -> api.getAllTermsByParentTerm (PredefinedParams.Examples.ontologyInfoExmp2) @>

////////
annotatorDocsv1.route <@ fun api -> api.getTermsForAdvancedSearch @>
|> annotatorDocsv1.alias "Get Terms Advanced Search (<code>getTermsForAdvancedSearch</code>)"
Expand Down
1 change: 1 addition & 0 deletions src/Server/Docs/DocsFunctions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module PredefinedParams =
module Examples =

let ontologyInfoExmp:OntologyInfo = OntologyInfo.create "Instrument Model" "MS:1000031"
let ontologyInfoExmp2:OntologyInfo = OntologyInfo.create "Q TRAP" "MS:1000187"

let unitOntologyExmp:DbDomain.Ontology = {
ID = 1L
Expand Down
101 changes: 101 additions & 0 deletions src/Server/OntologyDB.fs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,36 @@ let getTermSuggestionsByParentTerm cString (query:string, parentTerm:string) =
(reader.GetBoolean(6))
|]

let getTermSuggestionsByChildTerm cString (query:string, childTerm:string) =

use connection = establishConnection cString
connection.Open()
use getTermSuggestionsCmd = new MySqlCommand("getTermSuggestionsByChildTerm",connection)
getTermSuggestionsCmd.CommandType <- CommandType.StoredProcedure

let queryParam = getTermSuggestionsCmd.Parameters.Add("query",MySqlDbType.VarChar)
let childOntologyParam = getTermSuggestionsCmd.Parameters.Add("childOntology",MySqlDbType.VarChar)

queryParam .Value <- query
childOntologyParam .Value <- childTerm

use reader = getTermSuggestionsCmd.ExecuteReader()
[|
while reader.Read() do
yield
DbDomain.createTerm
(reader.GetInt64(0))
(reader.GetString(1))
(reader.GetInt64(2))
(reader.GetString(3))
(reader.GetString(4))
(if (reader.IsDBNull(5)) then
None
else
Some (reader.GetString(5)))
(reader.GetBoolean(6))
|]

let getTermByParentTermOntologyInfo cString (query:string, parentTerm:OntologyInfo) =

let hasAccession = parentTerm.TermAccession <> ""
Expand Down Expand Up @@ -240,6 +270,45 @@ let getAllTermsByParentTermOntologyInfo cString (parentTerm:OntologyInfo) =
(reader.GetBoolean(6))
|]

let getAllTermsByChildTermOntologyInfo cString (childTerm:OntologyInfo) =

let hasAccession = childTerm.TermAccession <> ""

use connection = establishConnection cString
connection.Open()
use cmd =
if hasAccession then
new MySqlCommand("getAllTermsByChildTermAndAccession",connection)
else
new MySqlCommand("getAllTermsByChildTerm",connection)

cmd.CommandType <- CommandType.StoredProcedure

let parentOntologyParam = cmd.Parameters.Add("childOntology",MySqlDbType.VarChar)

parentOntologyParam .Value <- childTerm.Name

if hasAccession then
let accessionParam = cmd.Parameters.Add("childTermAccession", MySqlDbType.VarChar)
accessionParam .Value <- childTerm.TermAccession

use reader = cmd.ExecuteReader()
[|
while reader.Read() do
yield
DbDomain.createTerm
(reader.GetInt64(0))
(reader.GetString(1))
(reader.GetInt64(2))
(reader.GetString(3))
(reader.GetString(4))
(if (reader.IsDBNull(5)) then
None
else
Some (reader.GetString(5)))
(reader.GetBoolean(6))
|]

let getTermSuggestionsByParentTermAndAccession cString (query:string, parentTerm:string, parentTermAccession:string) =

use connection = establishConnection cString
Expand Down Expand Up @@ -272,6 +341,38 @@ let getTermSuggestionsByParentTermAndAccession cString (query:string, parentTerm
(reader.GetBoolean(6))
|]

let getTermSuggestionsByChildTermAndAccession cString (query:string, childTerm:string, childTermAccession:string) =

use connection = establishConnection cString
connection.Open()
use getTermSuggestionsCmd = new MySqlCommand("getTermSuggestionsByChildTermAndAccession",connection)
getTermSuggestionsCmd.CommandType <- CommandType.StoredProcedure

let queryParam = getTermSuggestionsCmd.Parameters.Add("query",MySqlDbType.VarChar)
let childOntologyParam = getTermSuggestionsCmd.Parameters.Add("childOntology",MySqlDbType.VarChar)
let childTermAccessionParam = getTermSuggestionsCmd.Parameters.Add("childTermAccession",MySqlDbType.VarChar)

queryParam .Value <- query
childOntologyParam .Value <- childTerm
childTermAccessionParam.Value <- childTermAccession

use reader = getTermSuggestionsCmd.ExecuteReader()
[|
while reader.Read() do
yield
DbDomain.createTerm
(reader.GetInt64(0))
(reader.GetString(1))
(reader.GetInt64(2))
(reader.GetString(3))
(reader.GetString(4))
(if (reader.IsDBNull(5)) then
None
else
Some (reader.GetString(5)))
(reader.GetBoolean(6))
|]

let getUnitTermSuggestions cString (query:string) =

use connection = establishConnection cString
Expand Down
37 changes: 35 additions & 2 deletions src/Server/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,42 @@ let annotatorApi cString = {
getAllTermsByParentTerm = fun (parentTerm:OntologyInfo) ->
async {
let searchRes =
OntologyDB.getAllTermsByParentTermOntologyInfo
OntologyDB.getAllTermsByParentTermOntologyInfo cString parentTerm

return searchRes cString parentTerm
return searchRes
}

getTermSuggestionsByChildTerm = fun (max:int,typedSoFar:string,childTerm:OntologyInfo) ->
async {

let searchRes =
match typedSoFar with
| HelperFunctions.Regex HelperFunctions.isAccessionPattern foundAccession ->
OntologyDB.getTermByAccession cString foundAccession
| _ ->
let like =
if childTerm.TermAccession = ""
then
OntologyDB.getTermSuggestionsByChildTerm cString (typedSoFar,childTerm.Name)
else
OntologyDB.getTermSuggestionsByChildTermAndAccession cString (typedSoFar,childTerm.Name,childTerm.TermAccession)
let searchSet = typedSoFar |> Suggestion.createBigrams
like
|> Array.sortByDescending (fun sugg ->
Suggestion.sorensenDice (Suggestion.createBigrams sugg.Name) searchSet
)

|> fun x -> x |> Array.take (if x.Length > max then max else x.Length)

return searchRes
}

getAllTermsByChildTerm = fun (childTerm:OntologyInfo) ->
async {
let searchRes =
OntologyDB.getAllTermsByChildTermOntologyInfo cString childTerm

return searchRes
}

getTermsForAdvancedSearch = fun (ontOpt,searchName,mustContainName,searchDefinition,mustContainDefinition,keepObsolete) ->
Expand Down
4 changes: 2 additions & 2 deletions src/Server/Version.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ namespace System
open System.Reflection

[<assembly: AssemblyTitleAttribute("SWATE")>]
[<assembly: AssemblyVersionAttribute("0.4.5")>]
[<assembly: AssemblyVersionAttribute("0.4.6")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","12/03/2021")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "SWATE"
let [<Literal>] AssemblyVersion = "0.4.5"
let [<Literal>] AssemblyVersion = "0.4.6"
let [<Literal>] AssemblyMetadata_ReleaseDate = "12/03/2021"
4 changes: 4 additions & 0 deletions src/Shared/Shared.fs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ type IAnnotatorAPIv1 = {
getTermSuggestionsByParentTerm : (int*string*OntologyInfo) -> Async<DbDomain.Term []>
///
getAllTermsByParentTerm : OntologyInfo -> Async<DbDomain.Term []>
/// (nOfReturnedResults*queryString*parentOntology). If parentOntology = "" then isNull -> Error.
getTermSuggestionsByChildTerm : (int*string*OntologyInfo) -> Async<DbDomain.Term []>
///
getAllTermsByChildTerm : OntologyInfo -> Async<DbDomain.Term []>
/// (ontOpt,searchName,mustContainName,searchDefinition,mustContainDefinition,keepObsolete)
getTermsForAdvancedSearch : (DbDomain.Ontology option*string*string*string*string*bool) -> Async<DbDomain.Term []>

Expand Down

0 comments on commit 89aa7bc

Please sign in to comment.