Videos from JuliaCon are now available online
2018
Previous editions: 2017 | 2016 | 2015 | 2014
S. Hessam M. Mehr



Saving lives with Julia

Healthcare, law enforcement, and regulatory bodies worldwide are working hard to keep up with the recent outpour of new designer drugs hitting the streets. The poster child of the phenomenon, fentanyl, is a notoriously addictive synthetic opioid with numerous potent derivatives, some deadly in milligram quantities. Quite a few of these are routinely encountered in drug samples throughout Canada, often mixed with various cutting agents. Drug overdose related to fentanyls took the lives of 2,861 Canadians in 2016 alone. Whatever the appropriate response to the crisis, it would requires a new breed of analytical technique that can quickly differentiate between and quantify the many members of this growing zoo of opioids. To this end, a recent addition to the toolbox at Health Canada is nuclear magnetic resonance (NMR) spectroscopy, which studies the interaction between radiofrequency (RF) waves and atomic nuclei (typically hydrogen, i.e. proton) placed in a very strong magnetic field. The resulting spectra reflect the electronic/magnetic environment of each proton in a given chemical compound, giving an indication of its molecular structure. Although they provide a wealth of quantitative structural information about sample constituents, NMR spectra of complex mixtures are difficult to manually interpret, especially by non-experts. This is often the case with street drugs, where samples often contain 3-6 major components. Luckily, the NMR spectrum of a mixture can often be approximated by the linear combination of those of its constituents. We have used this property to write a Julia program that, given the NMR spectra for various compounds of interest, uses this mathematical decomposition scheme to find the exact composition of an unknown mixture. As always, things do get more complicated since the above relationship is only approximately true. In reality, mixing different chemicals together slightly modifies each compound’s contribution to the overall spectrum. Still, we found it straightforward to prototype and implement more robust implementations of the algorithm in Julia that could deal with this added complexity. The end result, NMR.jl, is the core project of the nascent JuliaNMR ecosystem on GitHub. NMR.jl aims to be a general-purpose NMR processing library and comes with state-of-the-art routines for automatic quantitative analysis of mixtures. Julia’s multiple dispatch semantics, excellent performance, and interactive development style allowed us to design much of the library in an exploratory manner and freely experiment with different ideas. This talk gives an overview of NMR.jl and how its spectral decomposition algorithm is being used at Health Canada’s Drug Analysis Service. We hope to demonstrate the unique features of the Julia programming language that helped quickly prototype and implement NMR.jl and the custom automation routines around it, all without sacrificing performance. Aside from the language itself, we hope to credit the excellent Julia libraries (e.g. Plots.jl) without which NMR.jl would not have been possible.

Speaker's bio

Hessam Mehr is an electrical engineer turned synthetic chemist who graduated from the University of British Columbia last year and badly misses the good old days of graduate school. Between September 2017 and March 2018, Hessam was working with Health Canada to develop techniques for analyzing drug samples using nuclear magnetic resonance. Currently, he is a post-doc at the University of Glasgow where he continues to spend his free time biking, learning new human and computer languages, practicing calligraphy (not very well at all), and baking bread.