<commit_before><!--
@Author: isa
@Date:   2016-05-13T16:37:00-04:00
@Last modified by:   isa
@Last modified time: 2016-05-19T16:12:10-04:00
-->



# NLM
## Utilities to interact with databases/APIs provided by the National Library of Medicine (NLM)
[![Build Status](https://travis-ci.org/bcbi/NLM.jl.svg?branch=master)](https://travis-ci.org/bcbi/NLM.jl)
Supported databases/APIS include:

- Entrez Programming Utilities (E-utilities) - http://www.ncbi.nlm.nih.gov/books/NBK25501/
- UML REST API - https://documentation.uts.nlm.nih.gov/rest/home.html
- Clinical Trials - https://clinicaltrials.gov/

### Installation
```{Julia}
Pkg.clone("https://github.com/bcbi/NLM.jl.git")
```


## Entrez

#### ESearch
```#Formulate PubMed search for 100 articles between 2000 and 2012
    #with obesity indicated as the major MeSH descriptor.
        println("------Searching Entrez--------")
        search_dic = Dict("db"=>"pubmed","term" => "obesity",
        "retstart" => 0, "retmax"=>100, "tool" =>"BioJulia",
        "email" => email, "mindate"=>"2000","maxdate"=>"2012" )
        esearch_response = esearch(search_dic)
        #convert response-xml to dictionary
        esearch_dict = eparse(esearch_response)
    ```    

#### EFetch
```     #Retrieve the list of ID's returned by esearch
        if !haskey(esearch_dict, "IdList")
            error("Error: IdList not found")
        end

        ids = []
        for id_node in esearch_dict["IdList"][1]["Id"]
            push!(ids, id_node)
        end

         #Define the fetch dictionary
        fetch_dic = Dict("db"=>"pubmed","tool" =>"BioJulia", "email" => email,
                         "retmode" => "xml", "rettype"=>"null")

        efetch_response = efetch(fetch_dic, ids)
        #convert response-xml to dictionary
        efetch_dict = eparse(efetch_response)

        #Optional - save the results of an entrez fetch to a sqlite database
        db = save_efetch(efetch_dict, db_path)

```<commit_msg>Updating readme<commit_after><!--
@Author: isa
@Date:   2016-05-13T16:37:00-04:00
@Last modified by:   isa
@Last modified time: 2016-05-19T16:12:10-04:00
-->



# NLM
## Utilities to interact with databases/APIs provided by the National Library of Medicine (NLM)
[![Build Status](https://travis-ci.org/bcbi/NLM.jl.svg?branch=master)](https://travis-ci.org/bcbi/NLM.jl)
Supported databases/APIS include:

- Entrez Programming Utilities (E-utilities) - http://www.ncbi.nlm.nih.gov/books/NBK25501/
- UML REST API - https://documentation.uts.nlm.nih.gov/rest/home.html
- Clinical Trials - https://clinicaltrials.gov/

### Installation
```{Julia}
Pkg.clone("https://github.com/bcbi/NLM.jl.git")
```


## Entrez

#### ESearch
Formulate a dictionary to search PubMed for 100 articles between 2000 and 2012
with obesity indicated as the major MeSH descriptor.
` println("------Searching Entrez--------")
    search_dic = Dict("db"=>"pubmed","term" => "obesity",
    "retstart" => 0, "retmax"=>100, "tool" =>"BioJulia",
    "email" => email, "mindate"=>"2000","maxdate"=>"2012" )`

Use esearch

` esearch_response = esearch(search_dic)`


Convert response-xml to dictionary

`esearch_dict = eparse(esearch_response)`  

#### EFetch
Retrieve the list of ID's returned by esearch
`   if !haskey(esearch_dict, "IdList")
        error("Error: IdList not found")
    end

    ids = []
    for id_node in esearch_dict["IdList"][1]["Id"]
        push!(ids, id_node)
    end`

Define the fetch dictionary
`fetch_dic = Dict("db"=>"pubmed","tool" =>"BioJulia", "email" => email,
                 "retmode" => "xml", "rettype"=>"null")

efetch_response = efetch(fetch_dic, ids)`
Convert response-xml to dictionary
`efetch_dict = eparse(efetch_response)`

Optional - save the results of an entrez fetch to a sqlite database
`db = save_efetch(efetch_dict, db_path)
`
{'fraction_non_alphanumeric': 0.16032537391760693, 'fraction_numerical': 0.03411178168459722, 'mean_word_length': 3.4480746791131853, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '157197', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1291, 'n_words': 304}