Best Dynamic Reverse Complement In Html/Javascript
4
2
Entering edit mode
13.4 years ago
Casbon ★ 3.3k

We should be ashamed of ourselves. All the web resources for reverse complementing a piece of DNA are straight from the 90s, requiring a round trip to the server and opening a new window. We can do better. (I'm not linking to any examples on purpose).

Please post a piece of HTML that computes the reverse complement for DNA entered into a textarea that dynamically displays the result using client side javascript. This should not require a form submit and therefore work without a server. Bonus points for handling degenerate characters correctly and preserving FASTA header lines.

codegolf • 7.0k views
ADD COMMENT
9
Entering edit mode

Personally, I think we should be ashamed with ourselves if we have to use a web-browser to reverse complement a sequence.

ADD REPLY
1
Entering edit mode
ADD REPLY
1
Entering edit mode

+1 This is a real javascript implementation. It opens a window, which may look like a CGI behavior. That website is really good. The developer has put a lot of efforts.

ADD REPLY
0
Entering edit mode

OK, so its client side but its not dynamic, right?

ADD REPLY
0
Entering edit mode

You mean copy and paste of sequence in the Textarea form should automatically generate reserve complement? Or if I keep on typing sequences in the Textarea should keep on generating reserve strand?

ADD REPLY
0
Entering edit mode

Personally I do not like another window with results popping out at the other corner of the screen but this is probably a matter of taste.

ADD REPLY
1
Entering edit mode

If you need to reverse complement a sequence as part of an application/pipeline, or if the sequence is large, I agree with GWW - you shouldn't consider a web solution (too slow, consumes network bandwidth). For once-off small tasks, I see nothing wrong with a web tool for convenience. @Casbon, if people are going to use the tool for small sequences, I don't think there is an urgent need for a completely client-side solution - savings are minimal. Out of interest, why are you asking the community to write this? Do you intend to make it available on a server?

ADD REPLY
0
Entering edit mode

When we look for troubles in alignments etc., having a web page like this would be convenient.

ADD REPLY
0
Entering edit mode

Writing a code reverse complement may look trivial, but if you do not want your tool to be substandard, please consider the features that a current user normally expacts: the correct handling of nucleotide ambiquity codes, preserving upper/lowercase, handling spaces/numbers/newlines/FASTA header as expected and the like.

ADD REPLY
3
Entering edit mode
13.4 years ago
lh3 33k

As an exercise. BTW, my favorite javascript program is this one.

ADD COMMENT
1
Entering edit mode

This is a link to the Editor for Phylogenetic Trees. It is not doing anything relevant to the question.

ADD REPLY
1
Entering edit mode
13.4 years ago

I've not time to answer for a reverse-complement sequence but I played with Mozilla XUL+javascript to translate a DNA sequence to protein: see my post here.

The code for your challenge would be nearly identical, and even shorter.

alt text

ADD COMMENT
0
Entering edit mode

All I get there is "Sorry, the page you were looking for in this blog does not exist. "

ADD REPLY
0
Entering edit mode

look closer: the URL in my post was cut by the biostars HTML renderer.

ADD REPLY
0
Entering edit mode

Note: The URL problem has now been fixed.

ADD REPLY
1
Entering edit mode
10.1 years ago

Since we're playing code golf, paste the following in your browser's address field or web/JS console, replacing the variable s with your sequence of interest:

javascript:s='ACGTT';o=s.split();for(i=0;i<s.length;i++)o[i]=s.charAt(i).replace(/[ACGTacgt]/g,function(c){return {'A':'T','C':'G','G':'C','T':'A','a':'t','c':'g','g':'c','t':'a'}[c];});alert(o.reverse().join(''));

If you want to handle a degenerate nucleotide case, just add its base to the regex in the replace call and its associated complement base in the callback function map function(c){...}.

$ echo "javascript:s='ACGTT'..." | wc -c
 215

Probably not too practical, but then code golf isn't about usability.

ADD COMMENT
0
Entering edit mode
12.2 years ago
Audriusa ▴ 10

In our site (reverse-complement.com) we have JavaScript based tools to compute reverse complement that preserves FASTA header and upper-lowercase regions (these can be used to mark various sequences of interest). We also have JavaScript based protein translator and the tool to convert between plain sequence and formatted GenBank representation, both ways. It is easy to share such services with anybody who is interested in as in comparison to server side solutions it scales very well.

ADD COMMENT

Login before adding your answer.

Traffic: 1892 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6