Comments (6)
I agree. I wanted to offer a quick fix that could be used now, and then failed to answer the original question. Sorry.
Note that a proper function should also work for wildcards and lowercase characters (and the example you gave is missing the "reversing" part.)
And then gave a bad answer too by not reversing... It's not a great day today.
I wouldn’t mind moving this to dnaio. Just as we have methods for slicing a SequenceRecord, computing a reverse complement is also a thing one regularly needs to do with DNA sequences, so it’s IMO natural to offer this.
I see cutadapt uses a translate table then reverses using Python. This is fast enough, but there are two caveats
- Python uses a dict to translate, because there are so many unicode code points. Since we guarantee 1-byte kind strings we can use a 256 character table. (bytes.maketrans automatically creates one of these as well).
- We can do the reversing and translation at the same time. Creating a new unicode object and then populating it with the translated nucleotides in reverse.
When we do that in Cython it should be quite a bit faster than the python method so this should also be a win for cutadapt.
SequenceRecord and BytesSequenceRecord can share the underlying method easily I think. Just as with the is_mate function.
from dnaio.
It is python builtin:
from dnaio import Sequence
complement_table = str.maketrans(dict(A="T", C="G", G="C", T="A"))
my_sequence = Sequence("my_seq", "GATTACA", "HHHHHHH")
my_sequence.sequence.translate(complement_table)
Results in 'CTAATGT'
Does this work for you?
from dnaio.
Reverse complements aren’t hard, but there are things one can get wrong, so it’s worth having a method for it. I would definitely not call it "built in". Note that a proper function should also work for wildcards and lowercase characters (and the example you gave is missing the "reversing" part.)
Here is what I use in Cutadapt:
https://github.com/marcelm/cutadapt/blob/26d3f39b6a37bcee8383d7d8f4a95879528137e4/src/cutadapt/utils.py#L172-L189
I wouldn’t mind moving this to dnaio. Just as we have methods for slicing a SequenceRecord, computing a reverse complement is also a thing one regularly needs to do with DNA sequences, so it’s IMO natural to offer this.
from dnaio.
Oh great, it sounded as if you were opposed to adding the functionality. And I’m of course all for speeding things up!
from dnaio.
Hi all,
Thanks so much for the comments. I'll have a go with str.maketrans and translate
Best
Jorge
from dnaio.
Thanks so much for the comments. I'll have a go with str.maketrans and translate
And for the reverse part there is a built-in reversed function: https://docs.python.org/3/library/functions.html#reversed . Good luck!
In the meantime we may hammer out a method, but I can give no ETA at this point. My time is rather limited now.
from dnaio.
Related Issues (20)
- ResourceWarnings HOT 3
- FastqFormatError, while reading in chunks HOT 5
- Use a newline index for FastqIter HOT 10
- Add ubam support HOT 11
- check quality score integrity HOT 1
- Version 1.0 HOT 3
- Typing warnings from mypy HOT 7
- How to cite dnaio in a manuscript? HOT 2
- Extended BAM support HOT 4
- _Py_NegativeRefcount error HOT 7
- Remove BytesSequenceRecord HOT 2
- API review: an alternative namo for `dnaio.open`? HOT 2
- Does SequenceRecord need to support the buffer protocol? HOT 2
- SequenceRecord array class HOT 6
- Three-way is mate comparison HOT 2
- Switch single&paired API to single&multiple API. HOT 2
- Compilation error HOT 3
- Identifying bottlenecks HOT 4
- compresslevel and open_threads should be arguments in the dnaio.open interface
- Add better type hints for dnaio.open()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dnaio.