dataesr/scientific-paragraphs-categorization huggingface dataset:
We constructed the ProPhyle k-mer indexes with a k-mer length optimized to minimize prediction delays (k=18, Methods). The obtained pneumococcal and gonococcal RASE databases occupy 321 MB and 242 MB RAM (4. 3× and 12× compression rate) and can be further compressed for transmission to 47 MB and 32 MB (29× and 90x compression rate), respectively (Supplementary Figure  1 ). This would allow RASE to be used on portable devices and its databases easily transmitted to the point of care over links with a limited bandwidth.
RASE identifies strains in the database within minutes We first examined two pneumococcal isolates that were used to build the RASE database (Table  1a , sens/spec 100%/100%, n=10) to test RASE can function in ideal circumstances. In the case of a fully susceptible isolate (SP01), the correct lineage and sequenced strain were identified within 1 minute and 7 minutes respectively. A multidrug-resistant isolate (SP02) was predicted even faster, with both lineage and the sequenced strain correctly detected and stabilized within 1 minute. To compare with gene-based approaches for detecting resistance  22  we evaluated how    Resistance categories in bold were inferred using ancestral reconstruction and were also confirmed using phenotypic testing (see Methods and Supplementary Table  3 ). Metagenomic samples are sorted by the estimated fraction of S.
pneumoniae reads. 23F R R R S (3) R R R R S S OoD Yes SP04 yes 12% 19A 19A R R R R R R R R R R (4) OoD Yes SP05 no 1. 8% 19F 19F R R R R! R R R R! R R! OoD Yes SP06 yes 8. 3% 23F 23F R R R S (3) R R R R S S SP10 yes 21% 5. 2% R R R R R R (8) SP11 yes 70% 14% R R R R R R ( 10 long it took for resistance genes to be sequenced on the device, and observed that at least 25 minutes would be needed for single copies to be detected (Supplementary Note 2). We then performed a similar evaluation with five gonococcal isolates from the database (Table  2a , sens/spec 57%/100%, n=20); however, here we selected more complicated cases. First, we tested a susceptible isolate (GC01), for which RASE identified the correct strain and antibiogram within 3 minutes of sequencing. We then sequenced an isolate with a novel and uncommon mechanism of cephalosporin resistance that has emerged recently (GC02)  35.
A subsequent analysis revealed that the ceftriaxone MIC of the sample was equal to the CDC GISP breakpoint (0. 125 μg/mL), whereas the best match in the database had an MIC of 0. 062 μg/mL, within a single doubling dilution. We further found that RASE performed well even with extremely poor data and low-quality reads (GC05,    1. and the antibiograms (benzylpenicillin, ceftriaxone, trimethoprim-sulfamethoxazole, erythromycin, and tetracycline resistance according to the EUCAST breakpoints  33  ). In all cases, the closest relative was identified within 5 minutes, even if the correct MLST sequence type was absent from the RASE database (an example shown in Figure  2 ). The two samples from the 23F clone (SP03 and SP06) were correctly called as being closely related to the Tennessee 23F-4 clone identified by PMEN, a clone strongly associated with macrolide resistance  36.
Consistent with this, the two samples were indeed resistant to erythromycin. However, the Tennessee 23F-4 clone was absent from the Massachusetts sample, with the best match being a comparatively distantly related strain that was penicillin resistant, but erythromycin susceptible. This illustrates the importance of a relevant database. We evaluated RASE with 14 clinical gonococcal isolates from the RaDAR-Go project  37  (Switzerland, 2015-2016) (Table  2b , sens/spec 93%/100%, n=56). These isolates were previously sequenced using nanopore and have full antibiograms available  38. The 55/56 correct calls indicate the strength of the genomic neighbor typing in a clinical setting. The only incorrect call (susceptibility to azithromycin in GC15) was marked as being low-confidence call on the basis of a poor susceptibility score.
Phenotyping is still informative but lower quality on highly divergent lineages As noted above, an important precondition of genomic neighbor typing is a comprehensive and relevant reference database. To evaluate RASE performance in a setting with an incomplete database, we used the gonococcal WHO 2016 reference strain collection  39. This includes a global collection of 14 diverse isolates from Europe, Asia, North America, and Australia, collected over 13 two decades and exhibiting phenotypes ranging from pan-susceptibility to multidrug resistance, and as such the GISP database is expected to be non-representative in this study. The WHO strains are available from the National Collection of Type Cultures, and were previously sequenced using nanopore  38  and genetically and phenotypically characterized  39.
Surprisingly, RASE correctly identified all MLST sequence types represented in the database and in 7 cases it provided fully correct resistance phenotypes (Supplementary Table  1 , sens/spec 67%/91%, n=56). In 6/7 cases where the complete resistance profile was not recovered, the closest relatives were identified correctly but were genetically divergent from the query isolates (Supplementary Note 6). In one case, the errors were due to a misidentification of the closest relatives by ProPhyle. Therefore, most prediction errors could be addressed with a more comprehensive database.
This sample was confirmed to be resistant to erythromycin, as well as clindamycin, tetracycline and oxacillin according to the EUCAST breakpoints  33. The original report of the Swedish 15A-25 clone did not report resistance to penicillin antibiotics  41  , which has subsequently emerged in this lineage. However, our database correctly identified the risk of penicillin resistance in this sample. The metagenomes SP11 and SP12 contain an estimated >20% reads that matched to S. pneumoniae, 14 and their serotypes were identified to be 15A and 3, respectively. The susceptibility scores of the best matches were fully consistent with the resistance profiles found in the samples, with the exception of tetracycline resistance in SP12 due to an incomplete database (Supplementary Note 7). The last remaining samples, SP07-SP09, contained less than 5% unambiguously pneumococcal reads.
Discussion This paper presents a method that we term genomic neighbor typing to pinpoint the closest relatives of a query genome within a suitable database and then to infer the phenotypic properties of the query strain on the basis of the reported properties of its relatives. At present, the precise lineage of a bacterial pathogen is often determined after most important clinical decisions have been made. However, incorporating genomic neighbor typing at an earlier stage offers a way of leveraging bacterial population structure to gain information on resistance and susceptibility, and inform antimicrobial therapy. The results from the metagenomic samples suggest that it is possible to apply this approach directly to clinical samples, and the success with both S. pneumoniae and N. gonorrhoeae indicates that it may have wide application.
16 As in all inference, the principle limitation of genomic neighbor typing is the representativeness of the database. While we have made use of relatively small samples from limited geographic areas to demonstrate proof of principle, in practice there are multiple examples of large genome databases generated by public health agencies, which could be combined with metadata on resistance for genomic neighbor typing. Such databases could, if necessary, be supplemented with local sampling. The relevant question for our approach therefore becomes whether the database contains a sufficiently high proportion of strains that will be encountered in the clinic and whether the resistance data are correct. Further work is required to determine the optimal structure and contents of databases for each application, but we emphasize the range of pathogens which appear to show promise for this approach.
These include E. coli, in which data on MLST type supplemented with epidemiologic information can consistently produce AUCs in excess of 0. 90 for multiple antibiotics  42  , suggesting great potential for neighbor typing to offer excellent resolution superior to MLST. However, genomic neighbor typing may be less suitable in the case where there is little genomic variation (e. g. , Mycobacterium tuberculosis) or when resistance emerges rapidly on independent and diverse genomic backgrounds (e. g. , Pseudomonas aeruginosa or resistance elements on highly promiscuous plasmids). In the case where the infectious agent is unknown this problem is significantly more challenging. K-mers from one pathogen can match others and produce false predictions, and so choice of the correct database for prediction is key.
Doing this will likely require a two-step solution in which the reads are first passed through a metagenomic classifier such as Centrifuge  43  or MetaMaps  44  , which would be used to select the correct RASE database on which to make a resistance call. Another limitation is the time required for sample preparation, which currently includes human DNA depletion, DNA isolation, and library preparation, taking a total of 4 hours. This is a rapidly evolving area of technology and automated rapid library preparation kits are already in development  45. Further advances in this space, in particular for the preparation of metagenomic samples, will be required to bring the method closer to the bedside. We have demonstrated that effectively predicting resistance and susceptibility from sequencing data does not require knowledge of causal resistance determinants.
In fact, neighbor typing only requires that the phenotype be sufficiently strongly associated with the population structure to make reliable predictions. A key advantage of this approach is that it requires very little genomic data, thus it is not limited by high error rates or low coverage. In particular, it is not attempting to define the exact genome sequence of the sample being tested, but merely which lineage it comes from. As a result, even when a small fraction of k-mers in the read are informative in matching to the RASE database, this is sufficient to call the lineage. This has the benefit of being faster than gene detection by virtue of the informative k-mers being distributed throughout the genome, and so more likely to appear in the first few reads sequenced by the nanopore. Therefore, the approach we present here can be seen as an application of compressed sensing: by measuring a sparse signal distributed broadly across our data we can identify it with comparatively few error-tolerant measurements.
Genomic neighbor typing can also be used to detect other phenotypes that are sufficiently tightly linked to a phylogeny, such as virulence. Further applications may include rapid outbreak investigations, as the closely related isolates involved in the outbreak would all be predicted to match to the same strain in the RASE database. The approach also lends itself to enhanced surveillance, including in the field; the 2014-2016 Ebola outbreak in West Africa, for example, saw MinION devices used in remote locations without advanced healthcare facilities 2. Finally, at present empiric treatment decisions are made within successive 'windows'  46  , in which increasing information becomes available, from initial Gram stain to full phenotypic characterization. The information from genomic neighbor typing is a natural complement to this process with the 18 potential to improve therapy long before it would become clinically apparent that the patient is not responding or before phenotypic susceptibility data were available.
Overview RASE uses rapid approximate k-mer-based matching of long sequencing reads against a database of strains to predict resistance via neighbor typing. The database contains a highly compressed exact k-mer index, a representation of the tree population structure, and metadata such as lineage, resistance profiles, MLST sequence type and serotype. The RASE prediction pipeline iterates over reads from the nanopore sequencer and provides real-time predictions of lineage and resistance or susceptibility (Figure  1 ).
Genomic neighbor typing All reference strains in the database are associated with similarity weights that are set to zero at the start of the run. Each time a new read is read from the stream, k-mer-based matching is applied to identify the strains with the maximum number of matching k-mers (see below). Such strains are read's nearest neighbors in the database according to the 1/('number of matched kmers') pseudodistance. The weights of the nearest neighbors are then increased according to the 'information content' of the read, calculated as the number of matched k-mers divided by the number of nearest neighbors. Reads that do not match (i. e. , 0 matching k-mers in the database) are not used in subsequent analysis. The computed matches are also used for updating the k-mer score (KS), which is the proportion of matched k-mers in all reads.
S. pneumoniae RASE database The S. pneumoniae RASE database was constructed with the EUCAST breakpoints 33 ([mg/L]): ceftriaxone (CRO): 0. 25, erythromycin (ERY): 0. 25, benzylpenicillin (PEN): 0. 06, trimethoprimsulfamethoxazole (SXT): 1. 00, and tetracycline (TET): 1. 00. While we have used the above values in the present work, others may be readily defined and the database rapidly updated. This is especially useful in the case where breakpoints may vary depending on the site of infection (as is the case with pneumococcal meningitis and otitis media, where lower MICs are considered to be resistant  33  ). The draft assemblies were downloaded from the SRA FTP server using the accession codes provided in Table  1  in ref  24. The phylogenetic tree was downloaded from DataDryad (accession: '10.
N. gonorrhoeae RASE database The N. gonorrhoeae RASE database was constructed with the CDC GISP breakpoints 34 ([mg/L]): azithromycin (AZM): 2. 0, cefixime (CFM): 0. 25, ciprofloxacin (CIP): 1. 0, and ceftriaxone (CRO): 0. 125. Before applying the breakpoints, azithromycin MICs for strains collected before 2005 were doubled in order to correct for the known inconsistencies of the phenotyping protocol due to a change in formulation of the commercial media  47.
23 The draft assemblies and the phylogenetic tree were downloaded from Zenodo (accession: '10. 5281/zenodo. 2618836'). Three prevalent types of plasmids  48  were downloaded from GenBank, localized in the GISP database using BLAST  49  , and removed from the dataset: the cryptic plasmid ('pJD1', GenBank accession 'NC_001377. 1'), the beta-lactamase plasmid ('pJD4', GenBank accession 'NC_002098. 1'), and the conjugative plasmid ('pEP5289', GenBank accession 'GU479466. 1'). The gonococcal ProPhyle index was constructed with the k-mer size k=18. The obtained N. gonorrhoeae RASE database including the code and source data is available from https://github. com/c2-d2/rase-db-ngonorrhoeae-gisp.
K-mer-based matching Reads were matched against the RASE databases using the ProPhyle classifier  27, 28  (commit b55e026) and its ProPhex component  50, 51. ProPhyle index stores k-mers of all strains in a highly compressed form, reducing the required memory footprint. In the database construction phase, the strains' k-mers are first propagated along the phylogenetic tree and then greedily assembled to contigs. The obtained contigs are then placed into a single text file, for which a BWT index is constructed  30. In the course of sequencing, each read is decomposed into overlapping k-mers. The k-mers are then searched in the BWT index by ProPhex using BWT search using a sliding window  50. For every k-mer, the obtained matches are translated back on the tree. This provides a list of nodes whose descending leaves are the strains containing that k-mer.
Comparison to Kraken For each RASE database, a fake NCBI taxonomy was generated from the database tree. Then a library was built using Kraken 31 (v1. 1. 1, with default parameters) from the same FASTA files as used for building the RASE database. Finally, Kraken databases were constructed for both k=18 and k=31. The obtained Kraken databases were used to classify reads from individual experiments. The obtained Kraken assignment were subsequently converted using an ad-hoc Python script to RASE-BAM (a subset of the BAM format 52 used by RASE). Finally, RASE prediction was applied on the BAM files, with the use of the RASE database metadata, and the results compared with the results of the standard RASE with ProPhyle.
Lower time estimates on resistance gene detection A complete genome of the multidrug-resistant SP02 isolate was assembled from the nanopore reads using the CANU 55 (version 1. 5, with default parameters). Prior to the assembly step, reads were filtered using SAMsift 56 based on the matching quality with the pneumococcal RASE database: only reads at least 1000bp long with at least 10% 18-mers shared with some of the reference draft assemblies were used. The obtained assembly was further corrected by Pilon 57 (version 1. 2, default parameters) using Illumina reads from the same isolate (taxid '1QJAP' in the SPARC dataset 24 ) mapped to the nanopore assembly using BWA-MEM 58 (version 0. 7. 17, with the default parameters) and sorted using SAMtools 52. The obtained assembly was searched for resistance-causing genes using the online CARD tool 8 (as of 2018/08/01).
Evaluation of the N. gonorrhoeae WHO samples To evaluate the predictions of the WHO samples, we inferred a phylogenetic tree from a data set comprising both the GISP isolates and the WHO isolates. First, reads were downloaded for the GISP isolates (NCBI BioProject: 'PRJEB2999' and 'PRJEB7904') and for the WHO isolates F-P (NCBI BioProject: 'PRJEB4024'). For the WHO isolates U-Z, read data were simulated from the finished de-novo assemblies (NCBI BioProject: 'PRJEB14020') using Art-Illumina 61 (version 2. 5. 1). Reads were mapped to the NCCP11945 reference genome (GenBank accession: 'CP001050. The closest relatives identified by RASE were verified using the obtained tree. For every WHO isolate, the obtained RASE prediction was compared to the closest GISP isolate on the tree.
MinION sequencing Sequencing was performed on the MinION MK1 device using R9. 4/FLO-MIN106 flow cells, according to the manufacturer's instructions. For experiments SP01-SP06, base-calling was performed using ONT Metrichor (versions 1. 6. 11 (SP01), 1. 7. 3 (SP02), 1. 7. 14 (SP03-SP06)) simultaneously with sequencing and all reads passing Metrichor quality check were used in the further analysis. For experiments SP07-SP12, the ONT MinKNOW software (versions 1. 4-1. 13. 1) was used to collect raw sequencing data and ONT Albacore (versions 1. 2. 2-2. 1. 10) was used for local base-calling of the raw data after sequencing runs were completed. For experiments GC01-GC05, ONT MinKNOW software was used to collect raw sequencing data and ONT Albacore (version 2. 3. 4) was used for local base-calling.
Results for all tested samples -isolates and metagenomes -are summarized in Supplementary Supplementary Note 6. We analyzed the results of the WHO gonococcal samples (Supplementary Table  1 ). First, we evaluated the RASE ability to predict MLST sequence types. In all cases, either RASE predicted the correct sequence type (n=9), or the true sequence type was not present in the reference database (n=5). The latter was the case only in the samples F through P, which belonged to the initial 2008 WHO reference panel and were collected primarily in the late 1990s, with the majority of specimens isolated from the Eastern Hemisphere 72. The GISP database, comprising strains collected in the US from 2000-2013, may not be representative then of the circulating lineages in those regions during that time span, which could result in both sequence type and antibiogram prediction errors.
However, we observed perfect prediction of sequence types in the additional 2016 WHO reference strains comprising U through Z that were collected in 2007 and onwards  39. We next sought to evaluate the resistance predictions. In 7 cases (F, K, N, O, P, U, W), the antibiograms were identified fully correctly; in 4 (G, V, X, Z) and 3 cases (L, M, Y) one and two mistakes were made, respectively. To explain these discrepancies, we inferred a recombinationcorrected phylogenetic tree comprising the GISP database isolates as well as the WHO samples (Supplementary File 1). With the exception of G and Y, the WHO isolates and their respective RASE-predicted best matches were the closest GISP isolates, indicative of accurate matching by RASE. While branch lengths of L, M and V on the tree reveal that the corresponding parts of the phylogeny are not well sampled in the database, the X, Y, and Z samples emerged from lineages that are well-represented but have acquired an atypically high level of cephalosporin resistance.
Whereas X and Z acquired a novel resistance-conferring mosaic penA allele  73  , Y acquired a novel active site mutation in the context of a pre-existing mosaic penA allele  74. While both of these adaptations resulted in high-level resistance, these mutations also appear to incur fitness costs in vitro and in the gonococcal mouse model  75. In line with this, these strains have only been sporadically observed in genomic surveillance of clinical isolates. These results highlight how ancestral or emerging resistant lineages may not be well-captured by sequence-based methods including RASE and emphasize the value of continuous updating of the RASE database for public health.
Supplementary Note 7. Further analysis of the reads from SP12 using Krocus 76 suggested that the pneumococcal DNA present was from the ST180 clonal complex, and matched specifically either to the sequence type ST180 or ST3798. This is consistent with identification as serotype 3, because this clonal complex contains the great majority of strains with this capsule type, which historically has not been associated with resistance  77. However, improved sampling and study of this lineage has recently found highly divergent subclades that are associated with resistance. These lineages were previously rare, and thus were less likely to be included in our database, but now are increasing in frequency  78. In this case, ST3798 is found to be in clade 1B, which is notable for exhibiting sporadic tetracycline resistance.
Size and memory footprint of the S. pneumoniae and N. gonorrhoeae RASE databases. The graph compares the size of the ProPhyle RASE index to the size of the original sequences: original draft assemblies (seq-fa), original draft assemblies compressed using gzip (seq-fagz), memory footprint of ProPhyle with the RASE index (ind-mem), and size of the ProPhyle RASE index compressed for transmission (ind-transm). Timeline of resistance genes. Number of occurrences of individual resistance genes in reads of SP02, as a function of time for the first hour of nanopore sequencing.
Delays in prediction based on the k-mer length. The plot displays delays in prediction as a function of the used k-mer length, for selected experiments and all possible k-mer lengths. Each horizontal panel displays times required for stabilization of one of the three predictions: the lineage, the alternative lineage, and the closest strain. Every column within a panel corresponds to a single k-mer length. When the required time exceeded 1 hour, the point is displayed at the top. Experiments where lineage could not be identified are plotted in red. The highlighted column corresponds to the k-mer length used for constructing the RASE databases in this paper. 50.
70SE was developed using Python, GNU Make, GNU Parallel 68 , Snakemake 69 , and the ETE 370and PySam 52 libraries, and was based on ProPhyle (commit b55e026). Bioconda 71 was used to ensure reproducibility of the software environments. All code, the generated databases and other supplementary materials are available under the MIT license from https://github. com/c2-d2/rase-supplement. The analyses in the paper were performed with the following versions of the RASE databases: "N. gonorrhoeae GISP USA v1. 4" and "S. pneumoniae SPARC USA v1. 3".