chambm / ahocorasicktrie Goto Github PK
View Code? Open in Web Editor NEWAn R package that implements fast searching for multiple keywords in multiple texts.
License: Apache License 2.0
An R package that implements fast searching for multiple keywords in multiple texts.
License: Apache License 2.0
Dear Matt,
the AhoCorasickTrie search does a super fast job. Really cool. I tried to do the same with the normal pattern matching functions from bioc Biostrings, but that took forever. Martin Morgan finally advised me to try your package. But I have a little problem regarding how it deals with names/labels of keywords. Here is an example from my code:
ref.proteome <- readAAStringSet(filepath = "uniprot-proteome_UP000000589.fasta")
n <- 10
peptides <- strip.mods(strip.ends(GluC.endpoint.peptide$ComparisonResult$Protein[1:n])) #first 10 peptides
names(peptides) <- GluC.endpoint.peptide$ComparisonResult$Protein[1:n] #put mod peptide as labels
proteins <- BiocGenerics::sapply(ref.proteome, toString) # full reference proteome
l <- AhoCorasickSearch(keywords = peptides, text = proteins, alphabet = "aminoacid", groupByKeyword = TRUE)
So far everything works perfectly, but the returned data structure looks like:
> head(l)
$ADLAEEYSKDR
$ADLAEEYSKDR[[1]]
$ADLAEEYSKDR[[1]]$Text
[1] "sp|P68037|UB2L3_MOUSE Ubiquitin-conjugating enzyme E2 L3 OS=Mus musculus GN=Ube2l3 PE=1 SV=1"
$ADLAEEYSKDR[[1]]$Offset
[1] 123
$ADLIAYLKKATNE
$ADLIAYLKKATNE[[1]]
$ADLIAYLKKATNE[[1]]$Text
[1] "sp|P62897|CYC_MOUSE Cytochrome c, somatic OS=Mus musculus GN=Cycs PE=1 SV=2"
$ADLIAYLKKATNE[[1]]$Offset
[1] 93
...
The labels of the keywords are lost! Instead the keywords as such are used as labels. Remember I took care to have a named vector of keywords (peptides) to not lose the associated modification pattern:
> names(peptides)
[1] "AAC[+57.0]YTK[+28.0]LLE" "AAK[+28.0]LAPEFAK[+28.0]R"
[3] "AAMQQDPVASSHK[+28.0]IDAK[+28.0]TYR" "AASQPGELK[+28.0]DWFVGR"
[5] "AC[+57.0]IPQSFTVDSSK[+28.0]AGLAPLEVR" "ADGYVLEGK[+28.0]EL"
[7] "ADLAEEYSK[+28.0]DR" "ADLEC[+57.0]TK[+28.0]PAA"
[9] "ADLIAYLK[+28.0]K[+28.0]ATNE" "ADLPTLGFTHFQPAQLTTVGK[+28.0]R"
Would it be possible to tweek the package in a way that the keyword AND text labels are preserved in the data structure returned by the matching function?
Greetings,
Tobias Kockmann
package version 0.1.2
library(AhoCorasickTrie)
# this works fine
keywords = c("Abra", "cadabra", "is", "the", "Magic", "Word")
str( AhoCorasickSearchList(keywords, list(c("What in", "the world"), c("is"), "secret about", "the Magic Word?")) )
# this crashes my R session in RStudio
str( AhoCorasickSearchList(keywords, list(c("What in", "the world"), c("is"), "secret about", "the Magic Word?"), alphabet = 'aminoacid') )
I quite like your package and it's focus, so have a suggestion that is meant to be constructive. List-of-list data structures are difficult and inefficient to deal with in R, and a good chunk of the community is into 'tidy' data which emphasizes 'long-form' data.frame-like structures. Thus the suggestion that the return value from, e.g.,
> keywords = c("AAA", "CC")
> text = c("CAAACCAAA", "CAAAC")
> res = AhoCorasickSearch(keywords, text)
might be
> res
Keyword Text_index Offset
1 AAA 1 2
2 CC 1 5
3 AAA 1 7
4 AAA 2 2
or perhaps Keyword_index
. I recognize that the list-of-lists representation will be a more memory-efficient representation when a keyword matches many locations in text.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.