├── .gitignore ├── README.md ├── bash └── batch_curl.sh ├── csharp ├── ncbo.sln └── ncbo │ ├── AnnotateText.cs │ ├── ClassesSearch.cs │ ├── Common │ ├── Constants.cs │ └── Network.cs │ ├── DataTypes │ ├── AnnotatedClass.cs │ ├── Annotation.cs │ ├── AnnotationCollection.cs │ ├── AnnotationLinks.cs │ ├── AnnotationResult.cs │ ├── Ontology.cs │ ├── OntologyLink.cs │ ├── Page.cs │ ├── PageCollection.cs │ ├── PageLink.cs │ ├── ResourceContext.cs │ ├── ResourceLinks.cs │ └── Resources.cs │ ├── GetLabels.cs │ ├── ListOntologies.cs │ ├── Program.cs │ ├── classes_search_terms.txt │ └── ncbo.csproj ├── github_actions └── publish_to_bioportal.yml ├── java ├── README.md ├── lib │ ├── jackson-annotations-2.1.4.jar │ ├── jackson-core-2.1.4.jar │ └── jackson-databind-2.1.4.jar └── src │ ├── AnnotateText.java │ ├── ClassesSearch.java │ ├── CreateMapping.java │ ├── GetLabels.java │ ├── ListOntologies.java │ └── classes_search_terms.txt ├── perl ├── annotate_text.pl ├── classes_search.pl ├── get_labels.pl └── list_ontologies.pl ├── python ├── python2 │ ├── annotate_text.py │ ├── classes_search.py │ ├── classes_search_terms.txt │ ├── get_labels.py │ └── list_ontologies.py └── python3 │ ├── annotate_text.py │ ├── classes_search.py │ ├── classes_search_terms.txt │ ├── get_labels.py │ └── list_ontologies.py └── ruby ├── add_new_ontology_submission.rb ├── annotate_text.rb ├── bioportal_ontologies_import.rb ├── classes_search.rb ├── classes_search_terms.txt ├── get_labels.rb └── list_ontologies.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.class 3 | /java/nbproject/private/ 4 | java/build.xml 5 | java/lib/CopyLibs/org-netbeans-modules-java-j2seproject-copylibstask.jar 6 | java/lib/nblibraries.properties 7 | java/manifest.mf 8 | java/nbproject/* 9 | /java/build/ 10 | /java/dist/ 11 | 12 | # IntelliJ 13 | java/.idea/* 14 | java/*.iml 15 | 16 | ## Ignore Visual Studio temporary files, build results, and 17 | ## files generated by popular Visual Studio add-ons. 18 | ## 19 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 20 | 21 | # User-specific files 22 | *.suo 23 | *.user 24 | *.userosscache 25 | *.sln.docstates 26 | 27 | # User-specific files (MonoDevelop/Xamarin Studio) 28 | *.userprefs 29 | 30 | # Build results 31 | [Dd]ebug/ 32 | [Dd]ebugPublic/ 33 | [Rr]elease/ 34 | [Rr]eleases/ 35 | x64/ 36 | x86/ 37 | bld/ 38 | [Bb]in/ 39 | [Oo]bj/ 40 | [Ll]og/ 41 | 42 | # Visual Studio 2015 cache/options directory 43 | .vs/ 44 | # Uncomment if you have tasks that create the project's static files in wwwroot 45 | #wwwroot/ 46 | 47 | # MSTest test Results 48 | [Tt]est[Rr]esult*/ 49 | [Bb]uild[Ll]og.* 50 | 51 | # NUNIT 52 | *.VisualState.xml 53 | TestResult.xml 54 | 55 | # Build Results of an ATL Project 56 | [Dd]ebugPS/ 57 | [Rr]eleasePS/ 58 | dlldata.c 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | **/Properties/launchSettings.json 65 | 66 | *_i.c 67 | *_p.c 68 | *_i.h 69 | *.ilk 70 | *.meta 71 | *.obj 72 | *.pch 73 | *.pdb 74 | *.pgc 75 | *.pgd 76 | *.rsp 77 | *.sbr 78 | *.tlb 79 | *.tli 80 | *.tlh 81 | *.tmp 82 | *.tmp_proj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # Visual Studio code coverage results 132 | *.coverage 133 | *.coveragexml 134 | 135 | # NCrunch 136 | _NCrunch_* 137 | .*crunch*.local.xml 138 | nCrunchTemp_* 139 | 140 | # MightyMoose 141 | *.mm.* 142 | AutoTest.Net/ 143 | 144 | # Web workbench (sass) 145 | .sass-cache/ 146 | 147 | # Installshield output folder 148 | [Ee]xpress/ 149 | 150 | # DocProject is a documentation generator add-in 151 | DocProject/buildhelp/ 152 | DocProject/Help/*.HxT 153 | DocProject/Help/*.HxC 154 | DocProject/Help/*.hhc 155 | DocProject/Help/*.hhk 156 | DocProject/Help/*.hhp 157 | DocProject/Help/Html2 158 | DocProject/Help/html 159 | 160 | # Click-Once directory 161 | publish/ 162 | 163 | # Publish Web Output 164 | *.[Pp]ublish.xml 165 | *.azurePubxml 166 | # TODO: Comment the next line if you want to checkin your web deploy settings 167 | # but database connection strings (with potential passwords) will be unencrypted 168 | *.pubxml 169 | *.publishproj 170 | 171 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 172 | # checkin your Azure Web App publish settings, but sensitive information contained 173 | # in these scripts will be unencrypted 174 | PublishScripts/ 175 | 176 | # NuGet Packages 177 | *.nupkg 178 | # The packages folder can be ignored because of Package Restore 179 | **/packages/* 180 | # except build/, which is used as an MSBuild target. 181 | !**/packages/build/ 182 | # Uncomment if necessary however generally it will be regenerated when needed 183 | #!**/packages/repositories.config 184 | # NuGet v3's project.json files produces more ignorable files 185 | *.nuget.props 186 | *.nuget.targets 187 | 188 | # Microsoft Azure Build Output 189 | csx/ 190 | *.build.csdef 191 | 192 | # Microsoft Azure Emulator 193 | ecf/ 194 | rcf/ 195 | 196 | # Windows Store app package directories and files 197 | AppPackages/ 198 | BundleArtifacts/ 199 | Package.StoreAssociation.xml 200 | _pkginfo.txt 201 | 202 | # Visual Studio cache files 203 | # files ending in .cache can be ignored 204 | *.[Cc]ache 205 | # but keep track of directories ending in .cache 206 | !*.[Cc]ache/ 207 | 208 | # Others 209 | ClientBin/ 210 | ~$* 211 | *~ 212 | *.dbmdl 213 | *.dbproj.schemaview 214 | *.jfm 215 | *.pfx 216 | *.publishsettings 217 | orleans.codegen.cs 218 | 219 | # Since there are multiple workflows, uncomment next line to ignore bower_components 220 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 221 | #bower_components/ 222 | 223 | # RIA/Silverlight projects 224 | Generated_Code/ 225 | 226 | # Backup & report files from converting an old project file 227 | # to a newer Visual Studio version. Backup files are not needed, 228 | # because we have git ;-) 229 | _UpgradeReport_Files/ 230 | Backup*/ 231 | UpgradeLog*.XML 232 | UpgradeLog*.htm 233 | 234 | # SQL Server files 235 | *.mdf 236 | *.ldf 237 | *.ndf 238 | 239 | # Business Intelligence projects 240 | *.rdl.data 241 | *.bim.layout 242 | *.bim_*.settings 243 | 244 | # Microsoft Fakes 245 | FakesAssemblies/ 246 | 247 | # GhostDoc plugin setting file 248 | *.GhostDoc.xml 249 | 250 | # Node.js Tools for Visual Studio 251 | .ntvs_analysis.dat 252 | node_modules/ 253 | 254 | # Typescript v1 declaration files 255 | typings/ 256 | 257 | # Visual Studio 6 build log 258 | *.plg 259 | 260 | # Visual Studio 6 workspace options file 261 | *.opt 262 | 263 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 264 | *.vbw 265 | 266 | # Visual Studio LightSwitch build output 267 | **/*.HTMLClient/GeneratedArtifacts 268 | **/*.DesktopClient/GeneratedArtifacts 269 | **/*.DesktopClient/ModelManifest.xml 270 | **/*.Server/GeneratedArtifacts 271 | **/*.Server/ModelManifest.xml 272 | _Pvt_Extensions 273 | 274 | # Paket dependency manager 275 | .paket/paket.exe 276 | paket-files/ 277 | 278 | # FAKE - F# Make 279 | .fake/ 280 | 281 | # JetBrains Rider 282 | .idea/ 283 | *.sln.iml 284 | 285 | # CodeRush 286 | .cr/ 287 | 288 | # Python Tools for Visual Studio (PTVS) 289 | __pycache__/ 290 | *.pyc 291 | 292 | # Cake - Uncomment if you are using it 293 | # tools/** 294 | # !tools/packages.config 295 | 296 | # Telerik's JustMock configuration file 297 | *.jmconfig 298 | 299 | # BizTalk build output 300 | *.btp.cs 301 | *.btm.cs 302 | *.odx.cs 303 | *.xsd.cs 304 | 305 | # Python virtualenv 306 | .venv/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NCBO REST Sample Code 2 | 3 | Sample code that demonstrates the use of the NCBO REST services. 4 | 5 | Documentation for REST services is available at [http://data.bioontology.org/documentation](http://data.bioontology.org/documentation) 6 | 7 | Questions and bug reports can be directed to the NCBO Support List: [support@bioontology.org](mailto:support@bioontology.org) 8 | 9 | ## Community Code Examples 10 | 11 | - [RNCBO](https://github.com/muntisa/RNCBO) (uses R) - Cristian R. Munteanu (BiGCaT - [www.enanomapper.net](http://www.enanomapper.net)) 12 | -------------------------------------------------------------------------------- /bash/batch_curl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #=============================================================================== 3 | # 4 | # FILE: batch_curl.sh 5 | # 6 | # USAGE: ./batch_curl.sh 7 | # 8 | # DESCRIPTION: 9 | # 10 | # OPTIONS: --- 11 | # REQUIREMENTS: --- 12 | # BUGS: --- 13 | # NOTES: --- 14 | # AUTHOR: Darren L. Weber, Ph.D. 15 | # COMPANY: Stanford University 16 | # VERSION: 1.0 17 | # CREATED: 03/04/2014 03:41:05 PM PST 18 | # REVISION: --- 19 | #=============================================================================== 20 | 21 | 22 | # TODO: add input arguments for APIKEY and json.txt file 23 | 24 | APIKEY='YOUR_API_KEY' 25 | 26 | # Example json content 27 | cat > json.txt <(annotationResult.AnnotatedClass.Link.Self); 17 | 18 | Console.WriteLine("Class details"); 19 | Console.WriteLine("\tID: " + annotationPage.ID); 20 | Console.WriteLine("\tPrefLabel: " + annotationPage.PrefLabel); 21 | Console.WriteLine("\tOntology: " + annotationPage.Links?.Ontology); 22 | 23 | Console.WriteLine("Annotation details"); 24 | foreach(Annotation annotation in annotationResult.Annotations) 25 | { 26 | Console.WriteLine("\tFrom: " + annotation.From); 27 | Console.WriteLine("\tTo: " + annotation.To); 28 | Console.WriteLine("\tMatch type: " + annotation.MatchType); 29 | } 30 | 31 | if(annotationResult.Hierarchy!=null && annotationResult.Hierarchy.Count > 0) 32 | { 33 | Console.WriteLine("Hierachy Annotations"); 34 | foreach (AnnotatedClass annotatedClass in annotationResult.Hierarchy) 35 | { 36 | AnnotationPage annotationHierarchyPage = 37 | Network.GetResponseAs(annotationResult.AnnotatedClass.Link.Self); 38 | 39 | Console.WriteLine("\tClass details"); 40 | Console.WriteLine("\t\tID: " + annotationHierarchyPage.ID); 41 | Console.WriteLine("\t\tPrefLabel: " + annotationHierarchyPage.PrefLabel); 42 | Console.WriteLine("\t\tOntology: " + annotationHierarchyPage.Links.Ontology); 43 | Console.WriteLine("\t\tDistance from originally annotated class: : " + annotatedClass.Distance); 44 | } 45 | } 46 | 47 | Console.WriteLine("===="); 48 | } 49 | } 50 | 51 | public static void DoIt() 52 | { 53 | string textToAnnotate = 54 | "Melanoma is a malignant tumor of melanocytes which are found " + 55 | "predominantly in skin but also in the bowel and the eye."; 56 | 57 | AnnotationResult[] annotationResults = 58 | Network.GetResponseAs(Constants.BaseUrl + "/annotator?text=" + textToAnnotate); 59 | 60 | PrintAnnotations(annotationResults); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /csharp/ncbo/ClassesSearch.cs: -------------------------------------------------------------------------------- 1 | using ncbo.Common; 2 | using ncbo.DataTypes; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Text; 7 | 8 | namespace ncbo 9 | { 10 | public static class ClassesSearch 11 | { 12 | public static void DoIt() 13 | { 14 | string[] lines = File.ReadAllLines("classes_search_terms.txt"); 15 | 16 | List allCollections = new List(); 17 | foreach(string line in lines) 18 | { 19 | Page page = 20 | Network.GetResponseAs("http://data.bioontology.org/search?q=" + line); 21 | 22 | foreach(PageCollection collection in page.Collections) 23 | { 24 | allCollections.Add(collection); 25 | } 26 | } 27 | 28 | foreach(PageCollection collection in allCollections) 29 | { 30 | Console.WriteLine(collection.ID); 31 | } 32 | return; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /csharp/ncbo/Common/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace ncbo.Common 6 | { 7 | public static class Constants 8 | { 9 | public static string BaseUrl = "http://data.bioontology.org"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /csharp/ncbo/Common/Network.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Net.Http; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace ncbo.Common 9 | { 10 | public static class Network 11 | { 12 | public static string GetJsonResponse(string url) 13 | { 14 | HttpClient web = new HttpClient(); 15 | web.DefaultRequestHeaders.Add("Authorization", "apikey token=5cddf159-a650-4458-b802-cb5936567668"); 16 | Task asyncResponse = web.GetAsync(url); 17 | asyncResponse.Wait(); 18 | HttpResponseMessage response = asyncResponse.Result; 19 | 20 | Task asyncString = response.Content.ReadAsStringAsync(); 21 | asyncString.Wait(); 22 | 23 | return asyncString.Result; 24 | } 25 | 26 | public static T GetResponseAs(string url) 27 | { 28 | string jsonResponse = GetJsonResponse(url); 29 | return JsonConvert.DeserializeObject(jsonResponse); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/AnnotatedClass.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class AnnotatedClass 9 | { 10 | [JsonProperty("links")] 11 | public AnnotationLinks Link { get; set; } 12 | [JsonProperty("distance")] 13 | public int Distance { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/Annotation.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class Annotation 9 | { 10 | [JsonProperty("from")] 11 | public int From { get; set; } 12 | [JsonProperty("to")] 13 | public int To { get; set; } 14 | [JsonProperty("matchType")] 15 | public string MatchType { get; set; } 16 | [JsonProperty("text")] 17 | public string Text { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/AnnotationCollection.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class AnnotationPage 9 | { 10 | [JsonProperty("@id")] 11 | public string ID { get; set; } 12 | [JsonProperty("prefLabel")] 13 | public string PrefLabel { get; set; } 14 | [JsonProperty("synonym")] 15 | public List Synonym { get; set; } 16 | [JsonProperty("definition")] 17 | public List Definition { get; set; } 18 | [JsonProperty("cui")] 19 | public List CUI { get; set; } 20 | [JsonProperty("semanticType")] 21 | public List SemanticType { get; set; } 22 | [JsonProperty("obsolete")] 23 | public bool Obsolete { get; set; } 24 | [JsonProperty("links")] 25 | public AnnotationLinks Links { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/AnnotationLinks.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace ncbo.DataTypes 4 | { 5 | public class AnnotationLinks 6 | { 7 | [JsonProperty("self")] 8 | public string Self { get; set; } 9 | [JsonProperty("ontology")] 10 | public string Ontology { get; set; } 11 | [JsonProperty("children")] 12 | public string Children { get; set; } 13 | [JsonProperty("parents")] 14 | public string Parents { get; set; } 15 | [JsonProperty("descendants")] 16 | public string Descendants { get; set; } 17 | [JsonProperty("ancestors")] 18 | public string Ancestors { get; set; } 19 | [JsonProperty("instances")] 20 | public string Instances { get; set; } 21 | [JsonProperty("tree")] 22 | public string Tree { get; set; } 23 | [JsonProperty("notes")] 24 | public string Notes { get; set; } 25 | [JsonProperty("mappings")] 26 | public string Mappings { get; set; } 27 | [JsonProperty("ui")] 28 | public string UI { get; set; } 29 | } 30 | } -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/AnnotationResult.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class AnnotationResult 9 | { 10 | [JsonProperty("annotatedClass")] 11 | public AnnotatedClass AnnotatedClass { get; set; } 12 | [JsonProperty("hierarchy")] 13 | public List Hierarchy { get; set; } 14 | [JsonProperty("annotations")] 15 | public List Annotations { get; set; } 16 | [JsonProperty("mappings")] 17 | public List Mappings { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/Ontology.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class Ontology 9 | { 10 | [JsonProperty("@id")] 11 | public string ID { get; set; } 12 | [JsonProperty("administeredBy")] 13 | public string[] AdministeredBy { get; set; } 14 | [JsonProperty("acronym")] 15 | public string Acronym { get; set; } 16 | [JsonProperty("name")] 17 | public string Name { get; set; } 18 | [JsonProperty("summaryOnly")] 19 | public string SummaryOnly { get; set; } 20 | [JsonProperty("ontologyType")] 21 | public string OntologyType { get; set; } 22 | [JsonProperty("links")] 23 | public OntologyLink Links { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/OntologyLink.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class OntologyLink 9 | { 10 | [JsonProperty("submissions")] 11 | public string Submissions { get; set; } 12 | [JsonProperty("properties")] 13 | public string Properties { get; set; } 14 | [JsonProperty("classes")] 15 | public string Classes { get; set; } 16 | [JsonProperty("single_class")] 17 | public string SingleClass { get; set; } 18 | [JsonProperty("roots")] 19 | public string Roots { get; set; } 20 | [JsonProperty("instances")] 21 | public string Instances { get; set; } 22 | [JsonProperty("metrics")] 23 | public string Metrics { get; set; } 24 | [JsonProperty("reviews")] 25 | public string Reviews { get; set; } 26 | [JsonProperty("notes")] 27 | public string Notes { get; set; } 28 | [JsonProperty("groups")] 29 | public string Groups { get; set; } 30 | [JsonProperty("categories")] 31 | public string Categories { get; set; } 32 | [JsonProperty("latest_submission")] 33 | public string LatestSubmission { get; set; } 34 | [JsonProperty("projects")] 35 | public string Projects { get; set; } 36 | [JsonProperty("download")] 37 | public string Download { get; set; } 38 | [JsonProperty("views")] 39 | public string Views { get; set; } 40 | [JsonProperty("analytics")] 41 | public string Analytics { get; set; } 42 | [JsonProperty("ui")] 43 | public string UI { get; set; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/Page.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class Page 9 | { 10 | [JsonProperty("page")] 11 | public int PageNumber { get; set; } 12 | [JsonProperty("pageCount")] 13 | public int PageCount { get; set; } 14 | [JsonProperty("totalCount")] 15 | public int TotalCount { get; set; } 16 | [JsonProperty("prevPage")] 17 | public string PrevPage { get; set; } 18 | [JsonProperty("nextPage")] 19 | public int? NextPageNumber { get; set; } 20 | [JsonProperty("links")] 21 | public PageLinks Link { get; set; } 22 | [JsonProperty("collection")] 23 | public List Collections { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/PageCollection.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class PageCollection 9 | { 10 | [JsonProperty("@id")] 11 | public string ID { get; set; } 12 | [JsonProperty("prefLabel")] 13 | public string PrefLabel { get; set; } 14 | [JsonProperty("synonym")] 15 | public List Synonym { get; set; } 16 | [JsonProperty("definition")] 17 | public List Definition { get; set; } 18 | [JsonProperty("cui")] 19 | public List CUI { get; set; } 20 | [JsonProperty("semanticType")] 21 | public List SemanticType { get; set; } 22 | [JsonProperty("obsolete")] 23 | public bool Obsolete { get; set; } 24 | [JsonProperty("links")] 25 | public PageLinks Links { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/PageLink.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class PageLinks 9 | { 10 | [JsonProperty("nextPage")] 11 | public string NextPageUrl { get; set; } 12 | [JsonProperty("prevPage")] 13 | public string PrevPageUrl { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/ResourceContext.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class ResourceContext 9 | { 10 | [JsonProperty("submissions")] 11 | public string Submissions { get; set; } 12 | [JsonProperty("notes")] 13 | public string Notes { get; set; } 14 | [JsonProperty("categories")] 15 | public string Categories { get; set; } 16 | [JsonProperty("provisional_classes")] 17 | public string ProvisionalClasses { get; set; } 18 | [JsonProperty("slices")] 19 | public string Slices { get; set; } 20 | [JsonProperty("metrics")] 21 | public string Metrics { get; set; } 22 | [JsonProperty("mappings")] 23 | public string Mappings { get; set; } 24 | [JsonProperty("users")] 25 | public string Users { get; set; } 26 | [JsonProperty("projects")] 27 | public string Projects { get; set; } 28 | [JsonProperty("ontologies")] 29 | public string Ontologies { get; set; } 30 | [JsonProperty("groups")] 31 | public string Groups { get; set; } 32 | [JsonProperty("replies")] 33 | public string Replies { get; set; } 34 | [JsonProperty("provisional_relations")] 35 | public string ProvisionalRelations { get; set; } 36 | [JsonProperty("reviews")] 37 | public string Reviews { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/ResourceLinks.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class ResourceLinks 9 | { 10 | [JsonProperty("submissions")] 11 | public string Submissions { get; set; } 12 | [JsonProperty("notes")] 13 | public string Notes { get; set; } 14 | [JsonProperty("categories")] 15 | public string Categories { get; set; } 16 | [JsonProperty("provisional_classes")] 17 | public string ProvisionalClasses { get; set; } 18 | [JsonProperty("annotator")] 19 | public string Annotator { get; set; } 20 | [JsonProperty("resource_index")] 21 | public string ResourceIndex { get; set; } 22 | [JsonProperty("documentation")] 23 | public string Documentation { get; set; } 24 | [JsonProperty("slices")] 25 | public string Slices { get; set; } 26 | [JsonProperty("metrics")] 27 | public string Metrics { get; set; } 28 | [JsonProperty("mappings")] 29 | public string Mappings { get; set; } 30 | [JsonProperty("users")] 31 | public string Users { get; set; } 32 | [JsonProperty("search")] 33 | public string Search { get; set; } 34 | [JsonProperty("projects")] 35 | public string Projects { get; set; } 36 | [JsonProperty("ontologies")] 37 | public string Ontologies { get; set; } 38 | [JsonProperty("ccv")] 39 | public string CCV { get; set; } 40 | [JsonProperty("recommender")] 41 | public string Recommender { get; set; } 42 | [JsonProperty("groups")] 43 | public string Groups { get; set; } 44 | [JsonProperty("replies")] 45 | public string Replies { get; set; } 46 | [JsonProperty("recommender_v1")] 47 | public string RecommenderV1 { get; set; } 48 | [JsonProperty("provisional_relations")] 49 | public string ProvisionalRelations { get; set; } 50 | [JsonProperty("property_search")] 51 | public string PropertySearch { get; set; } 52 | [JsonProperty("analytics")] 53 | public string Analytics { get; set; } 54 | [JsonProperty("reviews")] 55 | public string Reviews { get; set; } 56 | [JsonProperty("@context")] 57 | public ResourceContext Context { get; set; } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /csharp/ncbo/DataTypes/Resources.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace ncbo.DataTypes 7 | { 8 | public class Resources 9 | { 10 | [JsonProperty("links")] 11 | public ResourceLinks Links { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /csharp/ncbo/GetLabels.cs: -------------------------------------------------------------------------------- 1 | using ncbo.Common; 2 | using ncbo.DataTypes; 3 | using Newtonsoft.Json; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using System.Linq; 8 | 9 | namespace ncbo 10 | { 11 | public static class GetLabels 12 | { 13 | public static void DoIt() 14 | { 15 | // Get all ontologies from the REST service and parse the JSON 16 | Ontology[] ontology = Network.GetResponseAs(Constants.BaseUrl + "/ontologies"); 17 | 18 | Ontology broOntology = ontology.Where(n => n.Acronym == "BRO").FirstOrDefault(); 19 | 20 | string classesPageUrl = broOntology.Links.Classes; 21 | 22 | Page page = Network.GetResponseAs(classesPageUrl); 23 | 24 | List labels = new List(); 25 | for(;;) 26 | { 27 | string nextPageUrl = page.Link.NextPageUrl; 28 | foreach(PageCollection collection in page.Collections) 29 | { 30 | labels.Add(collection.PrefLabel); 31 | } 32 | 33 | if(!string.IsNullOrEmpty(nextPageUrl)) 34 | { 35 | page = Network.GetResponseAs(nextPageUrl); 36 | } 37 | else 38 | { 39 | break; 40 | } 41 | } 42 | 43 | foreach(string label in labels) 44 | { 45 | Console.WriteLine(label); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /csharp/ncbo/ListOntologies.cs: -------------------------------------------------------------------------------- 1 | using ncbo.Common; 2 | using ncbo.DataTypes; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Linq; 7 | 8 | namespace ncbo 9 | { 10 | public static class ListOntologies 11 | { 12 | public static void DoIt() 13 | { 14 | Resources resources = Network.GetResponseAs("http://data.bioontology.org"); 15 | 16 | Ontology[] ontologies = Network.GetResponseAs(resources.Links.Ontologies); 17 | 18 | IEnumerable ontologyStrings = ontologies.Select(n => n.Name + Environment.NewLine + 19 | n.ID + Environment.NewLine + Environment.NewLine); 20 | 21 | foreach(string ontologyString in ontologyStrings) 22 | { 23 | Console.WriteLine(ontologyString); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /csharp/ncbo/Program.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Net.Http; 6 | using System.Threading.Tasks; 7 | 8 | namespace ncbo 9 | { 10 | class Program 11 | { 12 | static void Main(string[] args) 13 | { 14 | Console.WriteLine("GetLabels:"); 15 | GetLabels.DoIt(); 16 | 17 | Console.WriteLine(); 18 | Console.WriteLine("AnnotateText:"); 19 | AnnotateText.DoIt(); 20 | 21 | Console.WriteLine(); 22 | Console.WriteLine("ClassesSearch"); 23 | ClassesSearch.DoIt(); 24 | 25 | Console.WriteLine(); 26 | Console.WriteLine("ListOntologies"); 27 | ListOntologies.DoIt(); 28 | 29 | Console.WriteLine("Done"); 30 | Console.ReadLine(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /csharp/ncbo/classes_search_terms.txt: -------------------------------------------------------------------------------- 1 | heart 2 | lung 3 | experiment 4 | human 5 | brain 6 | melanoma -------------------------------------------------------------------------------- /csharp/ncbo/ncbo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Exe 5 | netcoreapp1.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Always 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /github_actions/publish_to_bioportal.yml: -------------------------------------------------------------------------------- 1 | # This GitHub Actions workflow facilitates the activation of BioPortal's 2 | # remote ontology pull mechanism in response to the publication of a new 3 | # ontology version on GitHub. 4 | # Instead of relying on the daily scheduled pull, users can trigger the pull mechanism on demand. 5 | # 6 | # Requirements: 7 | # 8 | # 1. Ontology must be configured in BioPortal to be pulled from a URL. 9 | # 1. Ensure the presence of a GitHub repository secret BIOPORTAL_APIKEY containing APIKEY with 10 | # owner/administrative rights to ontology 11 | # 2. Replace ONTOLOGY_ACRONYM with the acronym of the ontology 12 | 13 | name: Publish to BioPortal 14 | 15 | on: 16 | release: 17 | types: [published] 18 | 19 | jobs: 20 | trigger_bioportal_pull: 21 | steps: 22 | - name: trigger_bioportal_pull 23 | run: | 24 | ONTOLOGY="ONTOLOGY_ACRONYM" 25 | API_ENDPOINT="https://data.bioontology.org/ontologies" 26 | AUTH="Authorization: apikey token=${{ secrets.BIOPORTAL_APIKEY }}" 27 | RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" -H "${AUTH}" -X POST "${API_ENDPOINT}/${ONTOLOGY}/pull") 28 | if [ $RESPONSE -ne "204" ]; then 29 | echo "FAILURE: API call resulted in $RESPONSE status code" 30 | exit 1 31 | else 32 | echo "SUCCESS: $RESPONSE" 33 | fi 34 | -------------------------------------------------------------------------------- /java/README.md: -------------------------------------------------------------------------------- 1 | # Java REST Examples 2 | 3 | To run a Java REST sample file, do the following: 4 | 5 | ## Windows 6 | From the src directory: 7 | 8 | - Compile: `javac -classpath ".;../lib/*" JavaFile.java` 9 | - Run: `java -classpath ".;../lib/*" JavaFile` 10 | - Replace `JavaFile` with the example you would like to run 11 | 12 | ## Linux / OS X 13 | From the src directory: 14 | 15 | - Compile: `javac -classpath ".:../lib/*" JavaFile.java` 16 | - Run: `java -classpath ".:../lib/*" JavaFile` 17 | - Replace `JavaFile` with the example you would like to run 18 | -------------------------------------------------------------------------------- /java/lib/jackson-annotations-2.1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ncbo/ncbo_rest_sample_code/cc2f2a291c81d8c292a4a26214146a55531cc06a/java/lib/jackson-annotations-2.1.4.jar -------------------------------------------------------------------------------- /java/lib/jackson-core-2.1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ncbo/ncbo_rest_sample_code/cc2f2a291c81d8c292a4a26214146a55531cc06a/java/lib/jackson-core-2.1.4.jar -------------------------------------------------------------------------------- /java/lib/jackson-databind-2.1.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ncbo/ncbo_rest_sample_code/cc2f2a291c81d8c292a4a26214146a55531cc06a/java/lib/jackson-databind-2.1.4.jar -------------------------------------------------------------------------------- /java/src/AnnotateText.java: -------------------------------------------------------------------------------- 1 | 2 | import com.fasterxml.jackson.core.JsonProcessingException; 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import java.io.BufferedReader; 6 | import java.io.DataOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStreamReader; 9 | import java.net.HttpURLConnection; 10 | import java.net.URL; 11 | import java.net.URLEncoder; 12 | 13 | public class AnnotateText { 14 | 15 | static final String REST_URL = "http://data.bioontology.org"; 16 | static final String API_KEY = ""; 17 | static final ObjectMapper mapper = new ObjectMapper(); 18 | 19 | public static void main(String[] args) throws Exception { 20 | String urlParameters; 21 | JsonNode annotations; 22 | String textToAnnotate = URLEncoder.encode("Melanoma is a malignant tumor of melanocytes which are found predominantly in skin but also in the bowel and the eye.", "ISO-8859-1"); 23 | 24 | // Get just annotations 25 | urlParameters = "text=" + textToAnnotate; 26 | annotations = jsonToNode(get(REST_URL + "/annotator?" + urlParameters)); 27 | printAnnotations(annotations); 28 | 29 | // Annotations with hierarchy 30 | urlParameters = "max_level=3&text=" + textToAnnotate; 31 | annotations = jsonToNode(get(REST_URL + "/annotator?" + urlParameters)); 32 | printAnnotations(annotations); 33 | 34 | // Annotations using POST (necessary for long text) 35 | urlParameters = "text=" + textToAnnotate; 36 | annotations = jsonToNode(post(REST_URL + "/annotator", urlParameters)); 37 | printAnnotations(annotations); 38 | 39 | // Get labels, synonyms, and definitions with returned annotations 40 | urlParameters = "include=prefLabel,synonym,definition&text=" + textToAnnotate; 41 | annotations = jsonToNode(get(REST_URL + "/annotator?" + urlParameters)); 42 | for (JsonNode annotation : annotations) { 43 | System.out.println(annotation.get("annotatedClass").get("prefLabel").asText()); 44 | } 45 | } 46 | 47 | private static void printAnnotations(JsonNode annotations) { 48 | for (JsonNode annotation : annotations) { 49 | // Get the details for the class that was found in the annotation and print 50 | JsonNode classDetails = jsonToNode(get(annotation.get("annotatedClass").get("links").get("self").asText())); 51 | System.out.println("Class details"); 52 | System.out.println("\tid: " + classDetails.get("@id").asText()); 53 | System.out.println("\tprefLabel: " + classDetails.get("prefLabel").asText()); 54 | System.out.println("\tontology: " + classDetails.get("links").get("ontology").asText()); 55 | System.out.println("\n"); 56 | 57 | JsonNode hierarchy = annotation.get("hierarchy"); 58 | // If we have hierarchy annotations, print the related class information as well 59 | if (hierarchy.isArray() && hierarchy.elements().hasNext()) { 60 | System.out.println("\tHierarchy annotations"); 61 | for (JsonNode hierarchyAnnotation : hierarchy) { 62 | classDetails = jsonToNode(get(hierarchyAnnotation.get("annotatedClass").get("links").get("self").asText())); 63 | System.out.println("\t\tClass details"); 64 | System.out.println("\t\t\tid: " + classDetails.get("@id").asText()); 65 | System.out.println("\t\t\tprefLabel: " + classDetails.get("prefLabel").asText()); 66 | System.out.println("\t\t\tontology: " + classDetails.get("links").get("ontology").asText()); 67 | } 68 | } 69 | } 70 | } 71 | 72 | private static JsonNode jsonToNode(String json) { 73 | JsonNode root = null; 74 | try { 75 | root = mapper.readTree(json); 76 | } catch (JsonProcessingException e) { 77 | e.printStackTrace(); 78 | } catch (IOException e) { 79 | e.printStackTrace(); 80 | } 81 | return root; 82 | } 83 | 84 | private static String get(String urlToGet) { 85 | URL url; 86 | HttpURLConnection conn; 87 | BufferedReader rd; 88 | String line; 89 | String result = ""; 90 | try { 91 | url = new URL(urlToGet); 92 | conn = (HttpURLConnection) url.openConnection(); 93 | conn.setRequestMethod("GET"); 94 | conn.setRequestProperty("Authorization", "apikey token=" + API_KEY); 95 | conn.setRequestProperty("Accept", "application/json"); 96 | rd = new BufferedReader( 97 | new InputStreamReader(conn.getInputStream())); 98 | while ((line = rd.readLine()) != null) { 99 | result += line; 100 | } 101 | rd.close(); 102 | } catch (Exception e) { 103 | e.printStackTrace(); 104 | } 105 | return result; 106 | } 107 | 108 | private static String post(String urlToGet, String urlParameters) { 109 | URL url; 110 | HttpURLConnection conn; 111 | 112 | String line; 113 | String result = ""; 114 | try { 115 | url = new URL(urlToGet); 116 | conn = (HttpURLConnection) url.openConnection(); 117 | conn.setDoOutput(true); 118 | conn.setDoInput(true); 119 | conn.setInstanceFollowRedirects(false); 120 | conn.setRequestMethod("POST"); 121 | conn.setRequestProperty("Authorization", "apikey token=" + API_KEY); 122 | conn.setRequestProperty("Accept", "application/json"); 123 | conn.setRequestProperty("charset", "utf-8"); 124 | conn.setUseCaches(false); 125 | 126 | DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); 127 | wr.writeBytes(urlParameters); 128 | wr.flush(); 129 | wr.close(); 130 | conn.disconnect(); 131 | 132 | BufferedReader rd = new BufferedReader( 133 | new InputStreamReader(conn.getInputStream())); 134 | while ((line = rd.readLine()) != null) { 135 | result += line; 136 | } 137 | rd.close(); 138 | } catch (Exception e) { 139 | e.printStackTrace(); 140 | } 141 | 142 | return result; 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /java/src/ClassesSearch.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | import java.util.ArrayList; 8 | import java.util.Scanner; 9 | import java.io.FileReader; 10 | 11 | import com.fasterxml.jackson.core.JsonProcessingException; 12 | import com.fasterxml.jackson.databind.JsonNode; 13 | import com.fasterxml.jackson.databind.ObjectMapper; 14 | import com.fasterxml.jackson.databind.ObjectWriter; 15 | 16 | public class ClassesSearch { 17 | 18 | static final String REST_URL = "http://data.bioontology.org"; 19 | static final String API_KEY = ""; 20 | static final ObjectMapper mapper = new ObjectMapper(); 21 | static final ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter(); 22 | 23 | public static void main(String[] args) throws Exception { 24 | ArrayList terms = new ArrayList(); 25 | 26 | String currentDir = System.getProperty("user.dir"); 27 | Scanner in = new Scanner(new FileReader(currentDir + "/src/classes_search_terms.txt")); 28 | 29 | while (in.hasNextLine()) { 30 | terms.add(in.nextLine()); 31 | } 32 | 33 | ArrayList searchResults = new ArrayList(); 34 | for (String term : terms) { 35 | JsonNode searchResult = jsonToNode(get(REST_URL + "/search?q=" + term)).get("collection"); 36 | searchResults.add(searchResult); 37 | } 38 | 39 | for (JsonNode result : searchResults) { 40 | System.out.println(writer.writeValueAsString(result)); 41 | } 42 | } 43 | 44 | private static JsonNode jsonToNode(String json) { 45 | JsonNode root = null; 46 | try { 47 | root = mapper.readTree(json); 48 | } catch (JsonProcessingException e) { 49 | e.printStackTrace(); 50 | } catch (IOException e) { 51 | e.printStackTrace(); 52 | } 53 | return root; 54 | } 55 | 56 | private static String get(String urlToGet) { 57 | URL url; 58 | HttpURLConnection conn; 59 | BufferedReader rd; 60 | String line; 61 | String result = ""; 62 | try { 63 | url = new URL(urlToGet); 64 | conn = (HttpURLConnection) url.openConnection(); 65 | conn.setRequestMethod("GET"); 66 | conn.setRequestProperty("Authorization", "apikey token=" + API_KEY); 67 | conn.setRequestProperty("Accept", "application/json"); 68 | rd = new BufferedReader( 69 | new InputStreamReader(conn.getInputStream())); 70 | while ((line = rd.readLine()) != null) { 71 | result += line; 72 | } 73 | rd.close(); 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | } 77 | return result; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /java/src/CreateMapping.java: -------------------------------------------------------------------------------- 1 | import com.fasterxml.jackson.core.JsonProcessingException; 2 | import com.fasterxml.jackson.databind.JsonNode; 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | 5 | import java.io.*; 6 | import java.lang.Exception; 7 | import java.lang.String; 8 | import java.net.HttpURLConnection; 9 | import java.net.URL; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class CreateMapping { 14 | 15 | static final String REST_URL = "http://data.bioontology.org"; 16 | private static final String API_KEY = ""; 17 | private static final ObjectMapper mapper = new ObjectMapper(); 18 | 19 | public static void main(String[] args) throws Exception { 20 | Mapping mapping = new Mapping(); 21 | mapping.setCreator("http://data.bioontology.org/user/{your username here}"); 22 | mapping.setRelation("http://www.w3.org/2002/07/owl#sameAs"); 23 | mapping.setSource("MY_USER"); 24 | mapping.setSource_name("MyUsers's Mapping Data"); 25 | mapping.setComment("This mapping creates a same as mapping between melanoma (NCIT) and melanoma (SNOMEDCT)"); 26 | 27 | // Create terms 28 | List terms = new ArrayList(); 29 | Term ncitMelanoma = new Term(); 30 | ncitMelanoma.setOntology("NCIT"); 31 | List ncitTermIds = new ArrayList(); 32 | ncitTermIds.add("http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C8711"); 33 | ncitMelanoma.setTerm(ncitTermIds); 34 | terms.add(ncitMelanoma); 35 | Term snomedMelanoma = new Term(); 36 | snomedMelanoma.setOntology("SNOMEDCT"); 37 | List snomedTermIds = new ArrayList(); 38 | snomedTermIds.add("http://purl.bioontology.org/ontology/SNOMEDCT/372244006"); 39 | snomedMelanoma.setTerm(snomedTermIds); 40 | terms.add(snomedMelanoma); 41 | mapping.setTerms(terms); 42 | 43 | // Convert mapping to JSON 44 | String prettyJSON = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mapping); 45 | String bodyJSON = mapper.writeValueAsString(mapping); 46 | System.out.println("Mapping as JSON:"); 47 | System.out.println(prettyJSON); 48 | System.out.println("\n\n"); 49 | 50 | // POST to web service 51 | postJSON(REST_URL + "/mappings", bodyJSON); 52 | 53 | // Success 54 | System.out.println("Added mapping successfully"); 55 | } 56 | 57 | private static String postJSON(String urlToGet, String body) { 58 | URL url; 59 | HttpURLConnection conn; 60 | 61 | String line; 62 | String result = ""; 63 | try { 64 | url = new URL(urlToGet); 65 | conn = (HttpURLConnection) url.openConnection(); 66 | conn.setDoOutput(true); 67 | conn.setDoInput(true); 68 | conn.setInstanceFollowRedirects(false); 69 | conn.setRequestMethod("POST"); 70 | conn.setRequestProperty("Authorization", "apikey token=" + API_KEY); 71 | conn.setRequestProperty("Accept", "application/json"); 72 | conn.setRequestProperty("Content-Type", "application/json"); 73 | conn.setRequestProperty("charset", "utf-8"); 74 | conn.setUseCaches(false); 75 | 76 | DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); 77 | wr.write(body.getBytes()); 78 | wr.flush(); 79 | wr.close(); 80 | conn.disconnect(); 81 | 82 | InputStream is; 83 | boolean error = false; 84 | if (conn.getResponseCode() >= 200 && conn.getResponseCode() < 400) { 85 | is = conn.getInputStream(); 86 | } else { 87 | error = true; 88 | is = conn.getErrorStream(); 89 | } 90 | 91 | BufferedReader rd = new BufferedReader( 92 | new InputStreamReader(is)); 93 | while ((line = rd.readLine()) != null) { 94 | result += line; 95 | } 96 | rd.close(); 97 | 98 | if (error) throw new Exception(result); 99 | } catch (Exception e) { 100 | e.printStackTrace(); 101 | } 102 | 103 | return result; 104 | } 105 | 106 | static class Term { 107 | private String ontology; 108 | private List term; 109 | 110 | public String getOntology() { 111 | return ontology; 112 | } 113 | 114 | public void setOntology(String ontology) { 115 | this.ontology = ontology; 116 | } 117 | 118 | public List getTerm() { 119 | return term; 120 | } 121 | 122 | public void setTerm(List term) { 123 | this.term = term; 124 | } 125 | } 126 | 127 | static class Mapping { 128 | private String creator; 129 | private String relation; 130 | private String source; 131 | private String source_name; 132 | private String comment; 133 | private List terms; 134 | 135 | public String getCreator() { 136 | return creator; 137 | } 138 | 139 | public void setCreator(String creator) { 140 | this.creator = creator; 141 | } 142 | 143 | public String getRelation() { 144 | return relation; 145 | } 146 | 147 | public void setRelation(String relation) { 148 | this.relation = relation; 149 | } 150 | 151 | public String getSource() { 152 | return source; 153 | } 154 | 155 | public void setSource(String source) { 156 | this.source = source; 157 | } 158 | 159 | public String getSource_name() { 160 | return source_name; 161 | } 162 | 163 | public void setSource_name(String source_name) { 164 | this.source_name = source_name; 165 | } 166 | 167 | public String getComment() { 168 | return comment; 169 | } 170 | 171 | public void setComment(String comment) { 172 | this.comment = comment; 173 | } 174 | 175 | public List getTerms() { 176 | return terms; 177 | } 178 | 179 | public void setTerms(List terms) { 180 | this.terms = terms; 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /java/src/GetLabels.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | import java.util.ArrayList; 8 | 9 | import com.fasterxml.jackson.core.JsonProcessingException; 10 | import com.fasterxml.jackson.databind.JsonNode; 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | 13 | public class GetLabels { 14 | 15 | static final String REST_URL = "http://data.bioontology.org"; 16 | static final String API_KEY = ""; 17 | static final ObjectMapper mapper = new ObjectMapper(); 18 | 19 | public static void main(String[] args) { 20 | ArrayList labels = new ArrayList(); 21 | 22 | // Get all ontologies from the REST service and parse the JSON 23 | String ontologies_string = get(REST_URL + "/ontologies"); 24 | JsonNode ontologies = jsonToNode(ontologies_string); 25 | 26 | // Iterate looking for ontology with acronym BRO 27 | JsonNode bro = null; 28 | for (JsonNode ontology : ontologies) { 29 | if (ontology.get("acronym").asText().equalsIgnoreCase("bro")) { 30 | bro = ontology; 31 | } 32 | } 33 | 34 | // Using the hypermedia link called `classes`, get the first page 35 | JsonNode page = jsonToNode(get(bro.get("links").get("classes").asText())); 36 | 37 | // From the returned page, get the hypermedia link to the next page 38 | String nextPage = page.get("links").get("nextPage").asText(); 39 | 40 | // Iterate over the available pages adding labels from all classes 41 | // When we hit the last page, the while loop will exit 42 | while (nextPage.length() != 0) { 43 | for (JsonNode cls : page.get("collection")) { 44 | if (!cls.get("prefLabel").isNull()) { 45 | labels.add(cls.get("prefLabel").asText()); 46 | } 47 | } 48 | 49 | if (!page.get("links").get("nextPage").isNull()) { 50 | nextPage = page.get("links").get("nextPage").asText(); 51 | page = jsonToNode(get(nextPage)); 52 | } else { 53 | nextPage = ""; 54 | } 55 | } 56 | 57 | // Print out all the labels 58 | for (String label : labels) { 59 | System.out.println(label); 60 | } 61 | } 62 | 63 | private static JsonNode jsonToNode(String json) { 64 | JsonNode root = null; 65 | try { 66 | root = mapper.readTree(json); 67 | } catch (JsonProcessingException e) { 68 | e.printStackTrace(); 69 | } catch (IOException e) { 70 | e.printStackTrace(); 71 | } 72 | return root; 73 | } 74 | 75 | private static String get(String urlToGet) { 76 | URL url; 77 | HttpURLConnection conn; 78 | BufferedReader rd; 79 | String line; 80 | String result = ""; 81 | try { 82 | url = new URL(urlToGet); 83 | conn = (HttpURLConnection) url.openConnection(); 84 | conn.setRequestMethod("GET"); 85 | conn.setRequestProperty("Authorization", "apikey token=" + API_KEY); 86 | conn.setRequestProperty("Accept", "application/json"); 87 | rd = new BufferedReader( 88 | new InputStreamReader(conn.getInputStream())); 89 | while ((line = rd.readLine()) != null) { 90 | result += line; 91 | } 92 | rd.close(); 93 | } catch (Exception e) { 94 | e.printStackTrace(); 95 | } 96 | return result; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /java/src/ListOntologies.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.BufferedReader; 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.net.HttpURLConnection; 6 | import java.net.URL; 7 | import java.util.ArrayList; 8 | 9 | import com.fasterxml.jackson.core.JsonProcessingException; 10 | import com.fasterxml.jackson.databind.JsonNode; 11 | import com.fasterxml.jackson.databind.ObjectMapper; 12 | import java.util.List; 13 | 14 | public class ListOntologies { 15 | 16 | static final String REST_URL = "http://data.bioontology.org"; 17 | static final String API_KEY = ""; 18 | static final ObjectMapper mapper = new ObjectMapper(); 19 | 20 | public static void main(String[] args) { 21 | // Get the available resources 22 | String resourcesString = get(REST_URL + "/"); 23 | JsonNode resources = jsonToNode(resourcesString); 24 | 25 | // Follow the ontologies link by looking for the media type in the list of links 26 | String link = resources.get("links").findValue("ontologies").asText(); 27 | 28 | // Get the ontologies from the link we found 29 | JsonNode ontologies = jsonToNode(get(link)); 30 | 31 | // Get the name and ontology id from the returned list 32 | List ontNames = new ArrayList(); 33 | for (JsonNode ontology : ontologies) { 34 | ontNames.add(ontology.get("name").asText() + "\n" + ontology.get("@id").asText() + "\n\n"); 35 | } 36 | 37 | // Print the names and ids 38 | for (String ontName : ontNames) { 39 | System.out.println(ontName); 40 | } 41 | } 42 | 43 | private static JsonNode jsonToNode(String json) { 44 | JsonNode root = null; 45 | try { 46 | root = mapper.readTree(json); 47 | } catch (JsonProcessingException e) { 48 | e.printStackTrace(); 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } 52 | return root; 53 | } 54 | 55 | private static String get(String urlToGet) { 56 | URL url; 57 | HttpURLConnection conn; 58 | BufferedReader rd; 59 | String line; 60 | String result = ""; 61 | try { 62 | url = new URL(urlToGet); 63 | conn = (HttpURLConnection) url.openConnection(); 64 | conn.setRequestMethod("GET"); 65 | conn.setRequestProperty("Authorization", "apikey token=" + API_KEY); 66 | conn.setRequestProperty("Accept", "application/json"); 67 | rd = new BufferedReader( 68 | new InputStreamReader(conn.getInputStream())); 69 | while ((line = rd.readLine()) != null) { 70 | result += line; 71 | } 72 | rd.close(); 73 | } catch (Exception e) { 74 | e.printStackTrace(); 75 | } 76 | return result; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /java/src/classes_search_terms.txt: -------------------------------------------------------------------------------- 1 | heart 2 | lung 3 | experiment 4 | human 5 | brain 6 | melanoma -------------------------------------------------------------------------------- /perl/annotate_text.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use LWP::Simple; # From CPAN 4 | use JSON qw( decode_json ); # From CPAN 5 | use Data::Dumper; # Perl core module 6 | use strict; # Good practice 7 | use warnings; # Good practice 8 | 9 | my $rest_url = "http://data.bioontology.org/"; 10 | my $api_key = ""; 11 | 12 | my $text_to_annotate = "Melanoma is a malignant tumor of melanocytes which are found predominantly in skin but also in the bowel and the eye."; 13 | 14 | # Get the top-level resources 15 | my $json = get( $rest_url . "?apikey=" . $api_key ); 16 | die "Could not get $rest_url!" unless defined $json; 17 | my $resources = decode_json( $json ); 18 | 19 | # Follow the links to the ontologies 20 | my $annotate_link = $resources->{'links'}->{'annotator'}; 21 | 22 | # Get the ontologies 23 | my $annotate_json = get( $annotate_link . "?text=" . $text_to_annotate . "&include=prefLabel&apikey=" . $api_key ); 24 | die "Could not get $annotate_link!" unless defined $annotate_json; 25 | my @classes = @{ decode_json( $annotate_json ) }; 26 | 27 | foreach my $ann (@classes) { 28 | my $cls = $ann->{'annotatedClass'}; 29 | print $cls->{'prefLabel'} . "\t" . $cls->{'@id'} . "\t" . $cls->{'links'}->{'ontology'} . "\n"; 30 | } 31 | -------------------------------------------------------------------------------- /perl/classes_search.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use LWP::Simple; # From CPAN 4 | use JSON qw( decode_json ); # From CPAN 5 | use Data::Dumper; # Perl core module 6 | use strict; # Good practice 7 | use warnings; # Good practice 8 | 9 | my $rest_url = "http://data.bioontology.org/"; 10 | my $api_key = ""; 11 | 12 | # Get the top-level resources 13 | my $json = get( $rest_url . "?apikey=" . $api_key ); 14 | die "Could not get $rest_url!" unless defined $json; 15 | my $resources = decode_json( $json ); 16 | 17 | # Follow the links to the ontologies 18 | my $search_link = $resources->{'links'}->{'search'}; 19 | 20 | # Get the ontologies 21 | my $search_json = get( $search_link . "?q=heart&apikey=" . $api_key ); 22 | die "Could not get $search_link!" unless defined $search_json; 23 | my $results = decode_json( $search_json ); 24 | my @classes = @{ $results->{'collection'} }; 25 | 26 | foreach my $cls (@classes) { 27 | print $cls->{'prefLabel'} . "\t" . $cls->{'@id'} . "\t" . $cls->{'links'}->{'ontology'} . "\n"; 28 | } 29 | -------------------------------------------------------------------------------- /perl/get_labels.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use LWP::Simple; # From CPAN 4 | use JSON qw( decode_json ); # From CPAN 5 | use Data::Dumper; # Perl core module 6 | use strict; # Good practice 7 | use warnings; # Good practice 8 | 9 | my $rest_url = "http://data.bioontology.org/"; 10 | my $api_key = ""; 11 | 12 | # Get the top-level resources 13 | my $json = get( $rest_url . "?apikey=" . $api_key ); 14 | die "Could not get $rest_url!" unless defined $json; 15 | my $resources = decode_json( $json ); 16 | 17 | # Follow the links to the ontologies 18 | my $ont_link = $resources->{'links'}->{'ontologies'}; 19 | 20 | # Get the ontologies 21 | my $ont_json = get( $ont_link . "?apikey=" . $api_key ); 22 | die "Could not get $ont_link!" unless defined $ont_json; 23 | my @ontologies = @{ decode_json( $ont_json ) }; 24 | 25 | my $bro; 26 | foreach my $ont (@ontologies) { 27 | if ($ont->{'acronym'} eq "BRO") { 28 | $bro = $ont; 29 | } 30 | } 31 | 32 | my $cls_page_link = $bro->{'links'}->{'classes'} . "?apikey=" . $api_key; 33 | 34 | # Get the labels for BRO 35 | my @classes; 36 | while ($cls_page_link) { 37 | my $page_json = get( $cls_page_link ); 38 | die "Could not get $cls_page_link!" unless defined $page_json; 39 | my $cls_page = decode_json( $page_json ); 40 | push @classes, @{ $cls_page->{'collection'} }; 41 | $cls_page_link = $cls_page->{'links'}->{'nextPage'}; 42 | } 43 | 44 | foreach my $cls (@classes) { 45 | print $cls->{'prefLabel'} . "\n"; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /perl/list_ontologies.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | use LWP::Simple; # From CPAN 4 | use JSON qw( decode_json ); # From CPAN 5 | use Data::Dumper; # Perl core module 6 | use strict; # Good practice 7 | use warnings; # Good practice 8 | 9 | my $rest_url = "http://data.bioontology.org/"; 10 | my $api_key = ""; 11 | 12 | # Get the top-level resources 13 | my $json = get( $rest_url . "?apikey=" . $api_key ); 14 | die "Could not get $rest_url!" unless defined $json; 15 | my $resources = decode_json( $json ); 16 | 17 | # Follow the links to the ontologies 18 | my $ont_link = $resources->{'links'}->{'ontologies'}; 19 | 20 | # Get the ontologies 21 | my $ont_json = get( $ont_link . "?apikey=" . $api_key ); 22 | die "Could not get $ont_link!" unless defined $ont_json; 23 | my @ontologies = @{ decode_json( $ont_json ) }; 24 | 25 | foreach my $ont (@ontologies) { 26 | print $ont->{'name'} . " (" . $ont->{'acronym'} . ")\n"; 27 | } 28 | -------------------------------------------------------------------------------- /python/python2/annotate_text.py: -------------------------------------------------------------------------------- 1 | import urllib2 2 | import json 3 | import os 4 | from pprint import pprint 5 | 6 | REST_URL = "http://data.bioontology.org" 7 | API_KEY = "" 8 | 9 | def get_json(url): 10 | opener = urllib2.build_opener() 11 | opener.addheaders = [('Authorization', 'apikey token=' + API_KEY)] 12 | return json.loads(opener.open(url).read()) 13 | 14 | def print_annotations(annotations, get_class=True): 15 | for result in annotations: 16 | class_details = get_json(result["annotatedClass"]["links"]["self"]) if get_class else result["annotatedClass"] 17 | print "Class details" 18 | print "\tid: " + class_details["@id"] 19 | print "\tprefLabel: " + class_details["prefLabel"] 20 | print "\tontology: " + class_details["links"]["ontology"] 21 | 22 | print "Annotation details" 23 | for annotation in result["annotations"]: 24 | print "\tfrom: " + str(annotation["from"]) 25 | print "\tto: " + str(annotation["to"]) 26 | print "\tmatch type: " + annotation["matchType"] 27 | 28 | if result["hierarchy"]: 29 | print "\n\tHierarchy annotations" 30 | for annotation in result["hierarchy"]: 31 | class_details = get_json(annotation["annotatedClass"]["links"]["self"]) 32 | pref_label = class_details["prefLabel"] or "no label" 33 | print "\t\tClass details" 34 | print "\t\t\tid: " + class_details["@id"] 35 | print "\t\t\tprefLabel: " + class_details["prefLabel"] 36 | print "\t\t\tontology: " + class_details["links"]["ontology"] 37 | print "\t\t\tdistance from originally annotated class: " + str(annotation["distance"]) 38 | 39 | print "\n\n" 40 | 41 | text_to_annotate = "Melanoma is a malignant tumor of melanocytes which are found predominantly in skin but also in the bowel and the eye." 42 | 43 | # Annotate using the provided text 44 | annotations = get_json(REST_URL + "/annotator?text=" + urllib2.quote(text_to_annotate)) 45 | 46 | # Print out annotation details 47 | print_annotations(annotations) 48 | 49 | # Annotate with hierarchy information 50 | annotations = get_json(REST_URL + "/annotator?max_level=3&text=" + urllib2.quote(text_to_annotate)) 51 | print_annotations(annotations) 52 | 53 | # Annotate with prefLabel, synonym, definition returned 54 | annotations = get_json(REST_URL + "/annotator?include=prefLabel,synonym,definition&text=" + urllib2.quote(text_to_annotate)) 55 | print_annotations(annotations, False) -------------------------------------------------------------------------------- /python/python2/classes_search.py: -------------------------------------------------------------------------------- 1 | import urllib2 2 | import json 3 | import os 4 | from pprint import pprint 5 | 6 | REST_URL = "http://data.bioontology.org" 7 | API_KEY = "" 8 | 9 | def get_json(url): 10 | opener = urllib2.build_opener() 11 | opener.addheaders = [('Authorization', 'apikey token=' + API_KEY)] 12 | return json.loads(opener.open(url).read()) 13 | 14 | # Get list of search terms 15 | path = os.path.join(os.path.dirname(__file__), 'classes_search_terms.txt') 16 | terms_file = open(path, "r") 17 | terms = [] 18 | for line in terms_file: 19 | terms.append(line) 20 | 21 | # Do a search for every term 22 | search_results = [] 23 | for term in terms: 24 | search_results.append(get_json(REST_URL + "/search?q=" + term)["collection"]) 25 | 26 | # Print the results 27 | for result in search_results: 28 | pprint(result) 29 | -------------------------------------------------------------------------------- /python/python2/classes_search_terms.txt: -------------------------------------------------------------------------------- 1 | heart 2 | lung 3 | experiment 4 | human 5 | brain 6 | melanoma -------------------------------------------------------------------------------- /python/python2/get_labels.py: -------------------------------------------------------------------------------- 1 | import urllib2 2 | import json 3 | 4 | REST_URL = "http://data.bioontology.org" 5 | API_KEY = "" 6 | 7 | 8 | def get_json(url): 9 | opener = urllib2.build_opener() 10 | opener.addheaders = [('Authorization', 'apikey token=' + API_KEY)] 11 | return json.loads(opener.open(url).read()) 12 | 13 | # Get all ontologies from the REST service and parse the JSON 14 | ontologies = get_json(REST_URL+"/ontologies") 15 | 16 | # Iterate looking for ontology with acronym BRO 17 | bro = None 18 | for ontology in ontologies: 19 | if ontology["acronym"] == "BRO": 20 | bro = ontology 21 | 22 | labels = [] 23 | 24 | # Using the hypermedia link called `classes`, get the first page 25 | page = get_json(bro["links"]["classes"]) 26 | 27 | # Iterate over the available pages adding labels from all classes 28 | # When we hit the last page, the while loop will exit 29 | next_page = page 30 | while next_page: 31 | next_page = page["links"]["nextPage"] 32 | for bro_class in page["collection"]: 33 | labels.append(bro_class["prefLabel"]) 34 | if next_page: 35 | page = get_json(next_page) 36 | 37 | # Output the labels 38 | for label in labels: 39 | print label 40 | -------------------------------------------------------------------------------- /python/python2/list_ontologies.py: -------------------------------------------------------------------------------- 1 | import urllib2 2 | import json 3 | import os 4 | from pprint import pprint 5 | 6 | REST_URL = "http://data.bioontology.org" 7 | API_KEY = "" 8 | 9 | def get_json(url): 10 | opener = urllib2.build_opener() 11 | opener.addheaders = [('Authorization', 'apikey token=' + API_KEY)] 12 | return json.loads(opener.open(url).read()) 13 | 14 | # Get the available resources 15 | resources = get_json(REST_URL + "/") 16 | 17 | # Follow the ontologies link by looking for the media type in the list of links 18 | media_type = "http://data.bioontology.org/metadata/Ontology" 19 | found_link = "" 20 | for link, link_type in resources["links"]["@context"].iteritems(): 21 | if media_type == link_type: 22 | found_link = link 23 | 24 | # Get the ontologies from the link we found 25 | ontologies = get_json(resources["links"][found_link]) 26 | 27 | # Get the name and ontology id from the returned list 28 | ontology_output = [] 29 | for ontology in ontologies: 30 | ontology_output.append(ontology["name"] + "\n" + ontology["@id"] + "\n\n") 31 | 32 | # Print the first ontology in the list 33 | pprint(ontologies[0]) 34 | 35 | # Print the names and ids 36 | print "\n\n" 37 | for ont in ontology_output: 38 | print ont 39 | 40 | -------------------------------------------------------------------------------- /python/python3/annotate_text.py: -------------------------------------------------------------------------------- 1 | import urllib.request, urllib.error, urllib.parse 2 | import json 3 | import os 4 | from pprint import pprint 5 | 6 | REST_URL = "http://data.bioontology.org" 7 | API_KEY = "" 8 | 9 | def get_json(url): 10 | opener = urllib.request.build_opener() 11 | opener.addheaders = [('Authorization', 'apikey token=' + API_KEY)] 12 | return json.loads(opener.open(url).read()) 13 | 14 | def print_annotations(annotations, get_class=True): 15 | for result in annotations: 16 | class_details = result["annotatedClass"] 17 | if get_class: 18 | try: 19 | class_details = get_json(result["annotatedClass"]["links"]["self"]) 20 | except urllib.error.HTTPError: 21 | print(f"Error retrieving {result['annotatedClass']['@id']}") 22 | continue 23 | print("Class details") 24 | print("\tid: " + class_details["@id"]) 25 | print("\tprefLabel: " + class_details["prefLabel"]) 26 | print("\tontology: " + class_details["links"]["ontology"]) 27 | 28 | print("Annotation details") 29 | for annotation in result["annotations"]: 30 | print("\tfrom: " + str(annotation["from"])) 31 | print("\tto: " + str(annotation["to"])) 32 | print("\tmatch type: " + annotation["matchType"]) 33 | 34 | if result["hierarchy"]: 35 | print("\n\tHierarchy annotations") 36 | for annotation in result["hierarchy"]: 37 | try: 38 | class_details = get_json(annotation["annotatedClass"]["links"]["self"]) 39 | except urllib.error.HTTPError: 40 | print(f"Error retrieving {annotation['annotatedClass']['@id']}") 41 | continue 42 | pref_label = class_details["prefLabel"] or "no label" 43 | print("\t\tClass details") 44 | print("\t\t\tid: " + class_details["@id"]) 45 | print("\t\t\tprefLabel: " + class_details["prefLabel"]) 46 | print("\t\t\tontology: " + class_details["links"]["ontology"]) 47 | print("\t\t\tdistance from originally annotated class: " + str(annotation["distance"])) 48 | 49 | print("\n\n") 50 | 51 | text_to_annotate = "Melanoma is a malignant tumor of melanocytes which are found predominantly in skin but also in the bowel and the eye." 52 | 53 | # Annotate using the provided text 54 | annotations = get_json(REST_URL + "/annotator?text=" + urllib.parse.quote(text_to_annotate)) 55 | 56 | # Print out annotation details 57 | print_annotations(annotations) 58 | 59 | # Annotate with hierarchy information 60 | annotations = get_json(REST_URL + "/annotator?max_level=3&text=" + urllib.parse.quote(text_to_annotate)) 61 | print_annotations(annotations) 62 | 63 | # Annotate with prefLabel, synonym, definition returned 64 | annotations = get_json(REST_URL + "/annotator?include=prefLabel,synonym,definition&text=" + urllib.parse.quote(text_to_annotate)) 65 | print_annotations(annotations, False) -------------------------------------------------------------------------------- /python/python3/classes_search.py: -------------------------------------------------------------------------------- 1 | import urllib.request, urllib.error, urllib.parse 2 | import json 3 | import os 4 | from pprint import pprint 5 | 6 | REST_URL = "http://data.bioontology.org" 7 | API_KEY = "" 8 | 9 | def get_json(url): 10 | opener = urllib.request.build_opener() 11 | opener.addheaders = [('Authorization', 'apikey token=' + API_KEY)] 12 | return json.loads(opener.open(url).read()) 13 | 14 | # Get list of search terms 15 | path = os.path.join(os.path.dirname(__file__), 'classes_search_terms.txt') 16 | terms_file = open(path, "r") 17 | terms = [] 18 | for line in terms_file: 19 | terms.append(line) 20 | 21 | # Do a search for every term 22 | search_results = [] 23 | for term in terms: 24 | search_results.append(get_json(REST_URL + "/search?q=" + term)["collection"]) 25 | 26 | # Print the results 27 | for result in search_results: 28 | pprint(result) 29 | -------------------------------------------------------------------------------- /python/python3/classes_search_terms.txt: -------------------------------------------------------------------------------- 1 | heart 2 | lung 3 | experiment 4 | human 5 | brain 6 | melanoma -------------------------------------------------------------------------------- /python/python3/get_labels.py: -------------------------------------------------------------------------------- 1 | import urllib.request, urllib.error, urllib.parse 2 | import json 3 | 4 | REST_URL = "http://data.bioontology.org" 5 | API_KEY = "" 6 | 7 | 8 | def get_json(url): 9 | opener = urllib.request.build_opener() 10 | opener.addheaders = [('Authorization', 'apikey token=' + API_KEY)] 11 | return json.loads(opener.open(url).read()) 12 | 13 | # Get all ontologies from the REST service and parse the JSON 14 | ontologies = get_json(REST_URL+"/ontologies") 15 | 16 | # Iterate looking for ontology with acronym BRO 17 | bro = None 18 | for ontology in ontologies: 19 | if ontology["acronym"] == "BRO": 20 | bro = ontology 21 | 22 | labels = [] 23 | 24 | # Using the hypermedia link called `classes`, get the first page 25 | page = get_json(bro["links"]["classes"]) 26 | 27 | # Iterate over the available pages adding labels from all classes 28 | # When we hit the last page, the while loop will exit 29 | next_page = page 30 | while next_page: 31 | next_page = page["links"]["nextPage"] 32 | for bro_class in page["collection"]: 33 | labels.append(bro_class["prefLabel"]) 34 | if next_page: 35 | page = get_json(next_page) 36 | 37 | # Output the labels 38 | for label in labels: 39 | print(label) 40 | -------------------------------------------------------------------------------- /python/python3/list_ontologies.py: -------------------------------------------------------------------------------- 1 | import urllib.request, urllib.error, urllib.parse 2 | import json 3 | import os 4 | from pprint import pprint 5 | 6 | REST_URL = "http://data.bioontology.org" 7 | API_KEY = "" 8 | 9 | def get_json(url): 10 | opener = urllib.request.build_opener() 11 | opener.addheaders = [('Authorization', 'apikey token=' + API_KEY)] 12 | return json.loads(opener.open(url).read()) 13 | 14 | # Get the available resources 15 | resources = get_json(REST_URL + "/") 16 | 17 | # Get the ontologies from the `ontologies` link 18 | ontologies = get_json(resources["links"]["ontologies"]) 19 | 20 | # Get the name and ontology id from the returned list 21 | ontology_output = [] 22 | for ontology in ontologies: 23 | ontology_output.append(f"{ontology['name']}\n{ontology['@id']}\n") 24 | 25 | # Print the first ontology in the list 26 | pprint(ontologies[0]) 27 | 28 | # Print the names and ids 29 | print("\n\n") 30 | for ont in ontology_output: 31 | print(ont) 32 | 33 | -------------------------------------------------------------------------------- /ruby/add_new_ontology_submission.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # Script for creating a new ontology submission and uploading an ontology file. 4 | # 5 | # Script requires APIKEY which is your bioportal.bioontology.org or ontoportal API key, 6 | # existing ontology and an onotology file. 7 | 8 | require 'rest-client' 9 | # APIKEY of the BioPortal/Ontoportal account 10 | APIKEY = 'YOUR-API-KEY' 11 | 12 | # URL of the BioPortal/Ontoportal API 13 | TARGET_API = 'https://data.bioontology.org' 14 | 15 | # The acronym of existing ontology 16 | ONTOLOGY = 'ABCD' 17 | 18 | # New Submission Details 19 | # hasOntologyLanguage options: OWL, UMLS, SKOS, OBO 20 | # status: alpha, beta, production, retired 21 | SUBMISSION_DETAILS = { 22 | 'contact': { 'name': 'Joe Blow', 'email': 'joe@example.com' }, 23 | 'hasOntologyLanguage': 'OWL', 24 | 'released': '2021-01-01', 25 | file: File.new("/path/to/your/ontology/file.owl.gz", 'rb'), 26 | 'description': 'Super Duper Ontology', 27 | 'status': 'production', 28 | 'version': '1.0' 29 | } 30 | 31 | response = RestClient::Request.execute( 32 | method: :post, 33 | url: "#{TARGET_API}/ontologies/#{ONTOLOGY}/submissions", 34 | payload: SUBMISSION_DETAILS, 35 | headers: { Authorization: "apikey token=#{APIKEY}" } 36 | ) 37 | 38 | puts response.code 39 | puts response 40 | -------------------------------------------------------------------------------- /ruby/annotate_text.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require 'open-uri' 3 | require 'cgi' 4 | 5 | REST_URL = "http://data.bioontology.org" 6 | API_KEY = "" 7 | 8 | def get_json(url) 9 | JSON.parse(open(url, "Authorization" => "apikey token=#{API_KEY}").read) 10 | end 11 | 12 | def puts_annotations(annotations, get_class = true) 13 | annotations.each do |result| 14 | class_details = get_class ? get_json(result["annotatedClass"]["links"]["self"]) : result["annotatedClass"] 15 | puts "Class details" 16 | puts "\tid: " + class_details["@id"] 17 | puts "\tprefLabel: " + class_details["prefLabel"] 18 | puts "\tontology: " + class_details["links"]["ontology"] 19 | 20 | puts "Annotation details" 21 | result["annotations"].each do |annotation| 22 | puts "\tfrom: #{annotation["from"]}" 23 | puts "\tto: #{annotation["to"]}" 24 | puts "\tmatch type: #{annotation["matchType"]}" 25 | end 26 | 27 | if !result["hierarchy"].empty? 28 | puts "\n\tHierarchy annotations" 29 | result["hierarchy"].each do |annotation| 30 | class_details = get_json(annotation["annotatedClass"]["links"]["self"]) 31 | pref_label = class_details["prefLabel"] or "no label" 32 | puts "\t\tClass details" 33 | puts "\t\t\tid: " + class_details["@id"] 34 | puts "\t\t\tprefLabel: " + class_details["prefLabel"] 35 | puts "\t\t\tontology: " + class_details["links"]["ontology"] 36 | puts "\t\t\tdistance from originally annotated class: " + annotation["distance"].to_s 37 | end 38 | end 39 | 40 | puts "\n\n" 41 | end 42 | end 43 | 44 | text_to_annotate = "Melanoma is a malignant tumor of melanocytes which are found predominantly in skin but also in the bowel and the eye." 45 | 46 | # Annotate using the provided text 47 | annotations = get_json(REST_URL + "/annotator?text=" + CGI.escape(text_to_annotate)) 48 | 49 | # Prints out annotation details 50 | puts_annotations(annotations) 51 | 52 | # Annotate with hierarchy information 53 | annotations = get_json(REST_URL + "/annotator?max_level=3&text=" + CGI.escape(text_to_annotate)) 54 | puts_annotations(annotations) 55 | 56 | # Annotate with prefLabel, synonym, definition returned 57 | annotations = get_json(REST_URL + "/annotator?include=prefLabel,synonym,definition&text=" + CGI.escape(text_to_annotate)) 58 | puts_annotations(annotations) -------------------------------------------------------------------------------- /ruby/bioportal_ontologies_import.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/ruby 2 | 3 | # A script by Vincent Emonet to auto import ontologies from a BioPortal appliance to another 4 | # It will import the metadata too 5 | # Fill the following variables with 6 | 7 | # URL of the API and APIKEY of the BioPortal we want to import data FROM 8 | SOURCE_API = "http://data.bioontology.org" 9 | SOURCE_APIKEY = "" 10 | 11 | # URL of the API and APIKEY of the BioPortal we want to import data TO 12 | TARGET_API = "http://agroportal.lirmm.fr" 13 | TARGET_APIKEY = "" 14 | 15 | # The username of the user that will have the administration rights on the ontology on the target portal 16 | TARGETED_PORTAL_USER = "admin" 17 | 18 | # The list of acronyms of ontologies to import 19 | ONTOLOGIES_TO_IMPORT = ["STY"] 20 | 21 | 22 | 23 | require 'json' 24 | require 'net/http' 25 | 26 | # A function to create a new ontology (if already Acronym already existing on the portal it will return HTTPConflict) 27 | def create_ontology(ont_info) 28 | uri = URI.parse(TARGET_API) 29 | http = Net::HTTP.new(uri.host, uri.port) 30 | 31 | req = Net::HTTP::Put.new("/ontologies/#{ont_info["acronym"]}") 32 | req['Content-Type'] = "application/json" 33 | req['Authorization'] = "apikey token=#{TARGET_APIKEY}" 34 | 35 | if (ont_info["viewingRestriction"] == "private") 36 | # In case of private ontology (acl: list of user that have the right to see the ontology) 37 | req.body = { "acronym": ont_info["acronym"], "name": ont_info["name"], "group": ont_info["group"], "hasDomain": ont_info["hasDomain"], "administeredBy": [TARGETED_PORTAL_USER], "viewingRestriction": "private", "acl": [TARGETED_PORTAL_USER]}.to_json 38 | else 39 | req.body = { "acronym": ont_info["acronym"], "name": ont_info["name"], "group": ont_info["group"], "hasDomain": ont_info["hasDomain"], "administeredBy": [TARGETED_PORTAL_USER]}.to_json 40 | end 41 | 42 | response = http.start do |http| 43 | http.request(req) 44 | end 45 | 46 | return response 47 | end 48 | 49 | # A function that take the submission informations from the source BioPortal to create a new submission 50 | # 2 possibilities: 51 | # - the source BioPortal pulls the ontology from an URL (pullLocation is filled), in this case we directly pull from this URL 52 | # - Or it stores it directly in the portal, in this case we pull it from the portal download link 53 | def upload_submission(sub_info) 54 | uri = URI.parse(TARGET_API) 55 | http = Net::HTTP.new(uri.host, uri.port) 56 | 57 | req = Net::HTTP::Post.new("/ontologies/#{sub_info["ontology"]["acronym"]}/submissions") 58 | req['Content-Type'] = "application/json" 59 | req['Authorization'] = "apikey token=#{TARGET_APIKEY}" 60 | 61 | # Check if the source BioPortal is pulling the ontology from an URL 62 | # If yes then we will pull the ontology from this place (allow auto update of the ontology when the ontology is changed in its source URL) 63 | if sub_info["pullLocation"].nil? 64 | pull_location = "#{sub_info["ontology"]["links"]["download"]}?apikey=#{SOURCE_APIKEY}" 65 | else 66 | pull_location = sub_info["pullLocation"] 67 | end 68 | 69 | # Extract contacts 70 | contacts = [] 71 | sub_info["contact"].each do |contact| 72 | contacts.push({"name": contact["name"],"email": contact["email"]}) 73 | end 74 | 75 | # Build the json body 76 | # hasOntologyLanguage options: OWL, UMLS, SKOS, OBO 77 | # status: alpha, beta, production, retired 78 | req.body = { 79 | "contact": contacts, 80 | "hasOntologyLanguage": sub_info["hasOntologyLanguage"], 81 | "released": sub_info["released"], 82 | "ontology": "#{TARGET_API}/ontologies/#{sub_info["ontology"]["acronym"]}", 83 | "description": sub_info["description"], 84 | "status": sub_info["status"], 85 | "version": sub_info["version"], 86 | "homepage": sub_info["homepage"], 87 | "documentation": sub_info["documentation"], 88 | "publication": sub_info["publication"], 89 | "naturalLanguage": sub_info["naturalLanguage"], 90 | "pullLocation": pull_location 91 | }.to_json 92 | 93 | #puts req.body.to_s 94 | response = http.start do |http| 95 | http.request(req) 96 | end 97 | 98 | return response 99 | end 100 | 101 | 102 | # Go through all ontologies acronym and get their latest_submission informations 103 | ONTOLOGIES_TO_IMPORT.each do |ont| 104 | sub_info = JSON.parse(Net::HTTP.get(URI.parse("#{SOURCE_API}/ontologies/#{ont}/latest_submission?apikey=#{SOURCE_APIKEY}&display=all"))) 105 | 106 | # if the ontology is already created then it will return HTTPConflict, no consequences 107 | puts create_ontology(sub_info["ontology"]) 108 | 109 | puts upload_submission(sub_info) 110 | end 111 | 112 | 113 | -------------------------------------------------------------------------------- /ruby/classes_search.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require 'open-uri' 3 | 4 | REST_URL = "http://data.bioontology.org" 5 | API_KEY = "" 6 | 7 | def get_json(url) 8 | JSON.parse(open(url, "Authorization" => "apikey token=#{API_KEY}").read) 9 | end 10 | 11 | # Get list of search terms 12 | path = File.expand_path('../classes_search_terms.txt', __FILE__) 13 | terms_file = open(path, "r") 14 | terms = [] 15 | terms_file.each {|line| terms << line} 16 | 17 | # Do a search for every term 18 | search_results = [] 19 | terms.each do |term| 20 | search_results << get_json(REST_URL + "/search?q=" + term)["collection"] 21 | end 22 | 23 | # Print the results 24 | require 'pp' 25 | pp search_results 26 | -------------------------------------------------------------------------------- /ruby/classes_search_terms.txt: -------------------------------------------------------------------------------- 1 | heart 2 | lung 3 | experiment 4 | human 5 | brain 6 | melanoma -------------------------------------------------------------------------------- /ruby/get_labels.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require 'open-uri' 3 | 4 | REST_URL = "http://data.bioontology.org" 5 | API_KEY = "" 6 | 7 | def get_json(url) 8 | JSON.parse(open(url, "Authorization" => "apikey token=#{API_KEY}").read) 9 | end 10 | 11 | # Get all ontologies from the REST service and parse the JSON 12 | ontologies = get_json(REST_URL+"/ontologies") 13 | 14 | # Iterate looking for ontology with acronym BRO 15 | bro = ontologies.select {|o| o["acronym"] == "BRO"}.shift 16 | 17 | labels = [] 18 | 19 | # Using the hypermedia link called `classes`, get the first page 20 | page = get_json(bro["links"]["classes"]) 21 | 22 | # Iterate over the available pages adding labels from all classes 23 | # When we hit the last page, the while loop will exit 24 | next_page = page 25 | while (next_page) 26 | next_page = page["links"]["nextPage"] 27 | page["class"].each do |cls| 28 | labels << cls["prefLabel"] 29 | end 30 | page = get_json(next_page) if next_page 31 | end 32 | 33 | # Output the labels 34 | labels.compact.each {|l| puts l} -------------------------------------------------------------------------------- /ruby/list_ontologies.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require 'open-uri' 3 | 4 | REST_URL = "http://data.bioontology.org" 5 | API_KEY = "" 6 | 7 | def get_json(url) 8 | JSON.parse(open(url, "Authorization" => "apikey token=#{API_KEY}").read) 9 | end 10 | 11 | # Get the available resources 12 | resources = get_json(REST_URL + "/") 13 | 14 | # Follow the ontologies link by looking for the media type in the list of links 15 | media_type = "http://data.bioontology.org/metadata/Ontology" 16 | link = resources["links"]["@context"].keep_if {|link,type| type.eql?(media_type)}.keys.first 17 | 18 | # Get the ontologies from the link we found 19 | ontologies = get_json(resources["links"][link]) 20 | 21 | # Get the name and ontology id from the returned list 22 | ontology_output = [] 23 | ontologies.each {|o| ontology_output << "#{o['name']}\n#{o['@id']}\n\n"} 24 | 25 | # Print the first ontology in the list 26 | require 'pp' 27 | pp ontologies.first 28 | 29 | # Print the names and ids 30 | puts "\n\n" 31 | ontology_output.each {|o| puts o} 32 | --------------------------------------------------------------------------------