Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description:
Provides functions to parse glycan structure text representations
into 'glyrepr' glycan structures. Currently, it supports StrucGP-style,
pGlyco-style, IUPAC-condensed, IUPAC-extended, IUPAC-short, IUPAC-compact,
WURCS, LINUCS, Linear Code, GlycoCT, KCF, and GlycoWorkbench formats. It
WURCS, LINUCS, Linear Code, GlycoCT, KCF, GlycoWorkbench, and SMILES. It
also provides an automatic parser to detect the format and parse the
structure string.
License: MIT + file LICENSE
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export(parse_kcf)
export(parse_linear_code)
export(parse_linucs)
export(parse_pglyco_struc)
export(parse_smiles)
export(parse_strucgp_struc)
export(parse_wurcs)
importFrom(Rcpp,evalCpp)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# glyparse (development version)

* New `parse_smiles()` function to parse glycan SMILES sequences. (#63)

* `parse_strucgp_struc()` rejects unmatched depth markers and malformed content instead of silently turning truncated input into valid structures. (#60)
* `parse_pglyco_struc()` and `auto_parse()` reject structures with unclosed pGlyco branches instead of silently accepting truncated input. (#59)
* `parse_iupac_short()` now preserves the base monosaccharide's donor carbon for modified residues, such as C2 for `Neu5Ac9Ac` and `Fru6S`, instead of incorrectly defaulting to C1.
Expand Down
65 changes: 65 additions & 0 deletions R/parse-smiles.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#' Parse Glycan SMILES
#'
#' Parse supported glycan SMILES into a [glyrepr::glycan_structure()] using
#' native R/C++ code. No chemical toolkit, network request, or database lookup
#' is required at runtime.
#'
#' @details
#' The parser reads the atom/bond graph, identifies sugar carbon backbones,
#' computes tetrahedral configurations from the SMILES neighbor order, and
#' constructs WURCS residue and linkage descriptors. These descriptors use
#' the same native residue mappings as [parse_wurcs()]. Different atom
#' traversals, branch orders, and ring labels do not change the result.
#'
#' Supported inputs are connected tree glycans with unbranched, saturated
#' carbon backbones of 5--9 atoms and five- or six-membered sugar rings, or
#' a reducing-end alditol (including terminal-deoxy alditols).
#' Supported chemistry includes the monosaccharides recognized by
#' `parse_wurcs()` within this scope, such as hexoses, pentoses, deoxy sugars,
#' hexosamines, uronic acids, and sialic acids. Supported substituents include
#' amino, N- and O-methyl/acetyl/glycolyl, neutral sulfate/phosphate groups,
#' and supported carboxyl derivatives such as methyl esters and amides.
#' Glycosidic bridges must be O-linked with at least one anomeric endpoint.
#'
#' Tetrahedral `@` and `@@` tags are interpreted relative to their neighbors,
#' including ring closures. Missing stereochemistry is never inferred from
#' common sugar identities or a database accession. An unknown configuration
#' is retained where the `glyrepr` vocabulary can express it; otherwise the
#' input fails. For non-reducing glycans with anomeric-to-anomeric bonds, a
#' deterministic root is chosen from the labeled residue graph. It may
#' differ from a WURCS file's conventional root without changing the glycan.
#' Alditol carbon chains are numbered deterministically using amino positions,
#' parent-sugar configuration, and the complete attached chemistry. Symmetric
#' alditols can therefore have reflected attachment positions relative to a
#' source WURCS, while describing the same molecule. Only a root alditol is
#' supported: non-root alditols fail rather than losing their reduced state.
#'
#' This is not a general-purpose SMILES reader. Unsupported syntax or chemistry
#' fails rather than being silently removed: examples include charges,
#' isotopes, separate explicit hydrogen atoms, aromatic atoms, stereochemical
#' classes other than tetrahedral `@`/`@@`, disconnected salts, aglycones,
#' open-chain sugars other than supported alditols, non-O glycosidic bonds,
#' non-anomeric inter-residue bridges, cyclic residue graphs,
#' and unrecognized modifications. Only neutral C, N, O, S, and P atoms are
#' accepted. Limits are 10,000 atoms and 52 residues per input. SMILES are not
#' detected by [auto_parse()]; call this function explicitly.
#'
#' @inheritParams parse_glycam_iupac
#' @return A [glyrepr::glycan_structure()] object.
#'
#' @examples
#' # Beta-D-glucose, GlyGen G71142DF / PubChem 64689
#' glucose <- "C([C@@H]1[C@H]([C@@H]([C@H]([C@@H](O1)O)O)O)O)O"
#' parse_smiles(glucose)
#' parse_smiles(c(glucose, NA, "not SMILES"), on_failure = "na")
#'
#' @seealso [parse_wurcs()]
#' @export
parse_smiles <- function(x, on_failure = "error", progress = FALSE) {
struc_parser_wrapper(
x,
"smiles",
on_failure = on_failure,
progress = progress
)
}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ knitr::opts_chunk$set(
Parse different glycan structure text nomenclature into `glyrepr::glycan_structure`.

Currently, the following formats are supported: IUPAC-extended, IUPAC-condensed,
IUPAC-short, IUPAC-compact, Glycam-IUPAC, WURCS, GlycoCT, GlycoWorkbench, KCF, LinearCode, Linucs, StrucGP-style, pGlyco-style.
IUPAC-short, IUPAC-compact, Glycam-IUPAC, WURCS, GlycoCT, GlycoWorkbench, KCF, LinearCode, Linucs, StrucGP-style, pGlyco-style, and glycan SMILES.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Parse different glycan structure text nomenclature into
Currently, the following formats are supported: IUPAC-extended,
IUPAC-condensed, IUPAC-short, IUPAC-compact, Glycam-IUPAC, WURCS,
GlycoCT, GlycoWorkbench, KCF, LinearCode, Linucs, StrucGP-style,
pGlyco-style.
pGlyco-style, and glycan SMILES.

## Installation

Expand Down
75 changes: 75 additions & 0 deletions man/parse_smiles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ Record parse_direct(const S &x, const S &format, const Vocab &v) {
}
if (format == "kcf")
return kcf(x, v);
if (format == "smiles")
return smiles_parse(x, v);
if (format == "wurcs")
return wurcs_parse(x, v);
if (format == "glycoct")
Expand Down
11 changes: 11 additions & 0 deletions src/native-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ Rcpp::List native_records_cpp(Rcpp::CharacterVector x, const std::string &format
}
// [[Rcpp::export]]
Rcpp::RObject native_aux_cpp(const std::string &op, Rcpp::List args, Rcpp::List vocabulary) {
if (op == "smiles_diagnostics") {
Rcpp::CharacterVector x = args["x"], result(x.size(), NA_STRING), error(x.size(), NA_STRING);
for (R_xlen_t i = 0; i < x.size(); ++i) {
if (x[i] == NA_STRING) continue;
Rcpp::checkUserInterrupt();
try { result[i] = gp::smiles_to_wurcs(Rcpp::as<std::string>(x[i])); }
catch (const std::exception &e) { error[i] = e.what(); }
}
return Rcpp::List::create(Rcpp::Named("wurcs")=result, Rcpp::Named("error")=error);
}

using namespace gp;
Vocab v(vocabulary);
if (starts(op, "wurcs_"))
Expand Down
2 changes: 2 additions & 0 deletions src/native.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ FloatingSub normalize_sub(const VI &, const VI &, S, const Slots &);
S convert(const S &, const S &, const Vocab &);
S detect(const S &, const Vocab &);
Record parse_direct(const S &, const S &, const Vocab &);
S smiles_to_wurcs(const S &);
Record smiles_parse(const S &, const Vocab &);
Record wurcs_parse(const S &, const Vocab &);
Record glycoct_parse(const S &, const Vocab &);
S gwb_convert(const S &, const Vocab &);
Expand Down
Loading
Loading