Created
November 29, 2012 16:53
-
-
Save radaniba/4170342 to your computer and use it in GitHub Desktop.
Parse fasta with Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #I found this stuff interesting to share, more on http://code.google.com/p/bio-js/ | |
| #This is my attempt at a bioinformatics framework in JavaScript. I've noticed more and more bioinformatics interfaces going live online, and so we are in a kind of cloud-computing era in bioinformatics. For example, there are many sites out there which let a user paste FASTA sequences into a web form. Things like parsing FASTA files should be easy to do and should be object oriented. I have decided on using the existing framework PrototypeJS to facilitate the process and to ensure that the project is compatible with most operating systems and browsers. | |
| #Example | |
| <html> | |
| <head> | |
| <title>Bio-JS Test</title> | |
| <script src='lib/prototype.js' type='text/javascript'></script> | |
| <script src='lib/Bio.js' type='text/javascript'></script> | |
| <!-- optional libraries --> | |
| <script src='lib/fauxconsole.js' type='text/javascript'></script> | |
| <!-- END optional libraries --> | |
| <script type='text/javascript'> | |
| <!-- | |
| Event.observe(window,"load",function(){ | |
| $$(".input").each(function(el){ | |
| el.update(">sequence1 descr1\nAAAAATT\n>sequence2 blabla\nAAAAAAAA"); | |
| }); | |
| }); | |
| function textareaToTextArea(){ | |
| fastaSequenceInput=$('test1').select('.input')[0]; | |
| fastaSequenceOutput=$('test1').select('.output')[0]; | |
| seqin=new Bio.SeqIO.fasta(fastaSequenceInput,{ | |
| html:false | |
| }); | |
| seqout=new Bio.SeqIO.fasta(fastaSequenceOutput,{ | |
| mode:"w", | |
| html:false | |
| }); | |
| while(seq=seqin.next_seq()){ | |
| seqout.write_seq(seq); | |
| } | |
| } | |
| function ioStringToTextArea(){ | |
| IO=new Bio.IO.String(); | |
| fastaSequenceInput=$('test2').select('.input')[0]; | |
| fastaSequenceOutput=$('test2').select('.output')[0]; | |
| // step 1: seqin to IO | |
| seqin=new Bio.SeqIO.fasta(fastaSequenceInput,{ | |
| html:false | |
| }); | |
| // seqout to the IO | |
| seqout=new Bio.SeqIO.fasta(IO,{ | |
| mode:"w", | |
| html:false | |
| }); | |
| while(seq=seqin.next_seq()){ | |
| seqout.write_seq(seq); | |
| } | |
| // step 2: IO to textarea | |
| seqin=new Bio.SeqIO.fasta(IO,{ | |
| html:false | |
| }); | |
| seqout=new Bio.SeqIO.fasta(fastaSequenceOutput,{ | |
| mode:"w", | |
| html:false | |
| }); | |
| while(seq=seqin.next_seq()){ | |
| seqout.write_seq(seq); | |
| } | |
| } | |
| //--> | |
| </script> | |
| <style type='text/css'> | |
| textarea.input,textarea.output{ | |
| height:6em; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <p>This is the demo page, which has clear source code for you to follow. Look at the <a href="doc/index.html">documentation</a> for details.</p> | |
| <table class="inputOutput"> | |
| <tr> | |
| <th colspan="2"> | |
| Input textarea to output textarea | |
| </th> | |
| </tr> | |
| <tr id='test1'> | |
| <td> | |
| <textarea class='input'></textarea> | |
| </td> | |
| <td> | |
| <textarea class='output'></textarea> | |
| </td> | |
| </tr> | |
| <tr> | |
| <td colspan="2" align='center'> | |
| <button onclick="javascript:textareaToTextArea();">Read/write</button> | |
| </td> | |
| </tr> | |
| <tr> | |
| <th colspan="2"> | |
| IO::String to output textarea | |
| </th> | |
| </tr> | |
| <tr id='test2'> | |
| <td><textarea class='input'></textarea></td> | |
| <td><textarea class='output'></textarea></td> | |
| </tr> | |
| <tr> | |
| <td colspan="2" align='center'> | |
| <button onclick="javascript:ioStringToTextArea();">Read/write</button> | |
| </td> | |
| </tr> | |
| </table> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment