<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Bringing Schemas to the Schemaless</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Mark A. Miller</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Rebecca C. Jackson</string-name>
          <email>rbca.jackson@gmail.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Christopher J. Mungall</string-name>
          <email>cjmungall@lbl.gov</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Bend Informatics</institution>
          ,
          <addr-line>Bend, OR</addr-line>
          ,
          <country country="US">USA</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Lawrence Berkeley National Laboratory</institution>
          ,
          <addr-line>Berkeley, CA</addr-line>
          ,
          <country country="US">USA</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>Ad-hoc spreadsheets can be appealing for managing some kinds of scientific data, but they allow bad practices like inconsistent types (e.g., string, integer, decimal) within individual columns, as well as open-ended categorical values (e.g., cell shapes). We have developed tools that infer LinkML schemas from spreadsheets, asserting types and enumerated lists that can be used to validate the dataset as it grows. Our tools can also associate OBO Foundry term identifiers with an enumeration's permissible values in the spirit of interoperability.</p>
      </abstract>
      <kwd-group>
        <kwd>1 LinkML</kwd>
        <kwd>spreadsheets</kwd>
        <kwd>schemas</kwd>
        <kwd>enumerations</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
    </sec>
    <sec id="sec-2">
      <title>2. Background</title>
      <p>We have developed a method for inferring a semantic model from the most common data
serializations, including delimited text files. In the case of CSV or TSV files, it is assumed that each
row represents one instance of a single class, each column header represents one predicate P, and the
contents of each cell represent the object of a P relationship with that instance. Patterns observed in the
columns can be used to specify the range of the predicates: all numerical columns would specify a
numerical range, columns with high entropy would specify a very open type, like String, and columns
with extensive re-use of a limited set of textual values would be interpreted as categorical objects,
perhaps the labels of classes that are defined elsewhere.</p>
      <p>Methods are provided for proposing term identifiers with the same semantics as the observed labels.
Specifically, the one term that best accounts for the longest span of cell contents is injected back into
the inferred model. We provide support for running term mappings against locally downloaded files or
over REST APIs, like that provided by OLS. We use SQLite for storing ontology content locally, so
installing a database engine is not required. While the results are almost guaranteed to include some
false positives and false negatives, the inclusion of lexical similarity metrics enables an expert reviewer
to rapidly curate the mappings.</p>
      <p>Inferred models are serialized in YAML, following the LinkML framework. This serialization can
be converted to a wide variety of formats familiar to ontologists, like RDF, OWL and JSON-LD, can
also be used to generate Python Dataclasses, and can drive validation, when converted to SHEX or
JSON schema. The mappings from categorical cell contents to term identifiers can also be saved as
SSSOM tables.</p>
    </sec>
    <sec id="sec-3">
      <title>3. Methods</title>
      <p>Our methods can be found in the turbomam/schemas-for-schemaless GitHub repository. There, we
illustrate the usefulness of this schema inference and mapping workflow with a table of microbial traits
from bacteria-archaea-traits/bacteria-archaea-traits. This repository aggregates over twenty sources of
knowledge about bacterial and archaeal traits. One use case for the tabular outputs from this repository,
such as condensed_species_NCBI.csv, is the construction of a knowledge graph such as
KnowledgeGraph-Hub/kg-microbe. If the knowledge graph is to succeed in sustainably linking even more data
sources, string values like “flask” the “cell_shape” column should be normalized to identifiers like
MICRO:0000406, which bears the label “pear-shaped cell” and the exact synonym “flask”.</p>
      <p>We start with a Makefile that:
• clones the linkml/linkml-model-enrichment GitHub repository
• clones bacteria-archaea-traits/bacteria-archaea-traits
applies the infer_model.py script from linkml-model-enrichment/linkml_model_enrichment to the
output/ condensed_traits_NCBI.csv file from bacteria-archaea-traits/output/ data file. An inferred
schema in the LinkML format, serialized as a YAML file, results
• downloads the rdftab executable
• downloads ontologies that we expected to be applicable to the bacterial traits file: pato.owl and
uberon.owl
• creates an SQLite database and populates it with statements from the downloaded OWL files,
using rdftab
The remainder of the workflow is implemented in Python:
• term ID and label pairs are quickly retrieved from the rdftab SQLite database
• The inferred LinkML schema for condensed_traits_NCBI.csv is parsed, and the permissible
values for the cell_shape column are extracted.
• The permissible values are sanitized with lowercasing, whitespace normalization and
replacement of several punctuation characters.
• A first pass of mapping the cell_shape_enum permissible values to OBO foundry terms is
performed by merging the sanitized values against the labels obtained from the rdftab SQLite
database.
• Sanitized cell_shape_enum permissible values that don’t match any labels from the rdftab
SQLite database are submitted to the OLS search API
• Additional metadata for each matching class is retrieved with a. sperate API call in order to
determine what kind of relationship justified the match (exact synonym from Genbank, close
synonym, etc.)
• One best OLS hit for each Sanitized cell_shape_enum is retained, based on relevance and string
similarity metrics.
• The term mappings from the rdftab SQLite and OLS paths are merged, and any Sanitized
cell_shape_enum permissible values that failed to map are reported
• The mappings are injected back into the LinkML model
4. Results</p>
      <p>condensed_traits_NCBI.csv consists of 172,325 taxon rows x 35 columns of identifiers, metadata
and traits. infer_model.py automatically infers that the following columns take enumerable values:
• cell_shape
• data_source
• gram_stain
• metabolism
• motility
• rRNA16S_genes
• range_salinity
• range_tmp
• sporulation
• superkingdom
infer_model.py can be forced to consider other columns as enumerable with the --enum-columns
flag. The cell_shape values in condensed_traits_NCBI.csv are already well normalized and the
sanitization step does not shrink the number of strings that require mappings:
• bacillus
• branced
• coccobacillus
• coccus
• disc filament
• flask
• fusiform
• irregular
• NA
• pleomorphic
• ring
• spindle
• spiral</p>
      <p>
        Four terms obtain mappings via merging with the rdftab database. (See Jupyter notebook for an
accounting [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ].) All of the remaining values obtain hits from the OLS search. However, seven values
do not retrieve any acceptable mappings. For example, the cosine string similarity between the sanitized
query and the best-matching annotation for the best matching term may be greater than our default
cutoff of 0.05. Seven of the OLS matches come from MICRO and one each comes from OMP or
NCBITAXON.
      </p>
    </sec>
    <sec id="sec-4">
      <title>5. Discussion</title>
      <p>Our method rapidly infers a schema from the bacterial and archaeal traits table and discovers
columns that appear to take enumerable values. Two methods are provided and demonstrated for
mapping the string representations of the enumerable values to terms from OBO Foundry ontologies.
The selection of those two methods is informed by one’s tolerance for downloading ontologies to local
storage vs depending upon a REST API. Visual inspection of the mappings suggests that they are all
sound. Mapping failures can be attributed to misspellings in the input (e.g., branced instead of branched)
or limitations placed on the search space. For example, our OLS search was limited to NCBITAXON,
MICRO and OMP. Had FMA been included, the cell morphology FMA:70989 would have been
discovered for the sanitized input ‘spindle’. Prioritizing quality over quantity, we were conservative in
our selection of ontologies.</p>
      <p>
        We have found that these methods work well for a variety of sources, including the INSDC
BioSample metadata collection [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. BioSample contains ~ 20 million records and ~ 500 entity types
and attributes, although we have only mapped a few attributes from tens of thousands of records at any
one time.
      </p>
      <p>Qualitatively speaking, the sensitivity and specificity of mapping gene names and symbols to OBO
Foundry terms has not been as good as it is for microbial traits, sequence features, and environmental
features. We are considering the addition of searches against gene or protein specific databases outside
of the OBO Foundry, like UniProt or Entrez Gene. Whether we would take a local download approach
or a REST API approach needs to be determined.</p>
    </sec>
    <sec id="sec-5">
      <title>6. Acknowledgements</title>
      <p>This work is supported in part by the Genomic Science Program in the U.S. Department of Energy,
Office of Science, Office of Biological and Environmental Research (BER) under contract number
DEAC02-05CH11231 (LBNL).</p>
    </sec>
    <sec id="sec-6">
      <title>7. References</title>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <surname>Ghada</surname>
            <given-names>AlTarawneh</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Simon Thorne</surname>
            ,
            <given-names>A Pilot</given-names>
          </string-name>
          <string-name>
            <surname>Study</surname>
          </string-name>
          <article-title>Exploring Spreadsheet Risk in Scientific Research</article-title>
          ,
          <source>in: Proceedings of the EuSpRIG 2016 Conference “Spreadsheet Risk Management”</source>
          , pp.
          <fpage>49</fpage>
          -
          <lpage>69</lpage>
          . ISBN:
          <fpage>978</fpage>
          -1-
          <fpage>905404</fpage>
          -53-
          <lpage>7</lpage>
          . URL: https://arxiv.org/abs/1703.09785
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>[2] URL: https://www.ebi.ac.uk/ols/docs/api</mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>[3] URL: https://github.com/mapping-commons/SSSOM</mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>[4] URL: https://github.com/ontodev/rdftab.rs</mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>[5] URL: https://github.com/linkml/linkml</mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>[6] URL: https://github.com/turbomam/schemas-for-schemaless/blob/main/notebooks/schemasfor-schemaless.ipynb</mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>[7] URL: https://www.ncbi.nlm.nih.gov/biosample/</mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>