I wrote a bioinformatics package in golang,
in which I used a function to check whether a letter(
byte) is a valid DNA/RNA/Protein letter.
The easy way is storing the letters of alphabet in a map and check the existance of a letter.
However, when I used
go tool pprof to profile the performance,
I found the hash functions (
map cost much time (see figure below).
Then I found a faster way: storing letters in a slice.
In detail, saving a letter(
byte) at position
int(letter) of slice.
To check a letter, just chech the value of
slice[int(letter)], non-zero means
See the benchmark result:
BenchmarkCheckLetterWithMap 2000000000 0.20 ns/op
BenchmarkCheckLetterWithSlice 2000000000 0.01 ns/op
[updates] I wrote a tool to do the same job and it’s even more powerful.
This post presents a script for fetching taxon information by species name or taxid.
Take home message:
1). using cache to avoid repeatly search
2). object of
Entrez.read(Entrez.efetch()) could be treated as
but it could not be rightly pickled. Using Json is also not OK.
The right way is cache the xml text.
search = Entrez.efetch(id=taxid, db="taxonomy", retmode="xml") # data = Entrez.read(search) ## read and parse xml data_xml = search.read() data = list(Entrez.parse(StringIO(data_xml)))
3). pickle file was fragile. A flag file could be used to detect whether data is rightly dumped.
4). using multi-threads to accelerate fetching.
It’s too heavy to my VPS, even with cache plugin. Static page is much more faster!
See official doc: http://gohugo.io/