Coder Social home page Coder Social logo

ahocorasicktrie's People

Contributors

chambm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ahocorasicktrie's Issues

loss of keyword labels

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

Crash rather than error when alphabet = 'aminoacid'

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') )

data.frame-like return value?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.