{"id":409,"date":"2013-03-26T12:26:47","date_gmt":"2013-03-26T12:26:47","guid":{"rendered":"http:\/\/blopig.com\/blog\/?p=409"},"modified":"2013-03-26T12:33:12","modified_gmt":"2013-03-26T12:33:12","slug":"a-javascript-function-to-validate-fasta-sequences","status":"publish","type":"post","link":"https:\/\/www.blopig.com\/blog\/2013\/03\/a-javascript-function-to-validate-fasta-sequences\/","title":{"rendered":"A javascript function to validate FASTA sequences"},"content":{"rendered":"<p>I was more than a bit annoyed of not finding this out there in the interwebs, being a strong encourager of googling (or in Jamie&#8217;s case <a title=\"Duck Duck Go ~ The alternative search engine\" href=\"https:\/\/duckduckgo.com\/\" target=\"_blank\">duck-duck-going<\/a>) and re-use.<\/p>\n<p>So I proffer my very own fasta validation javascript function.<\/p>\n<pre class=\"toolbar:2 wrap:true show-plain:3 plain-toggle:false lang:js decode:true\" title=\"Javascript FASTA sequence validation\">\/*\r\n * Validates (true\/false) a single fasta sequence string\r\n * param   fasta    the string containing a putative single fasta sequence\r\n * returns boolean  true if string contains single fasta sequence, false \r\n *                  otherwise \r\n *\/\r\nfunction validateFasta(fasta) {\r\n\r\n\tif (!fasta) { \/\/ check there is something first of all\r\n\t\treturn false;\r\n\t}\r\n\r\n\t\/\/ immediately remove trailing spaces\r\n\tfasta = fasta.trim();\r\n\r\n\t\/\/ split on newlines... \r\n\tvar lines = fasta.split('\\n');\r\n\r\n\t\/\/ check for header\r\n\tif (fasta[0] == '&gt;') {\r\n\t\t\/\/ remove one line, starting at the first position\r\n\t\tlines.splice(0, 1);\r\n\t}\r\n\r\n\t\/\/ join the array back into a single string without newlines and \r\n\t\/\/ trailing or leading spaces\r\n\tfasta = lines.join('').trim();\r\n\r\n\tif (!fasta) { \/\/ is it empty whatever we collected ? re-check not efficient \r\n\t\treturn false;\r\n\t}\r\n\r\n\t\/\/ note that the empty string is caught above\r\n\t\/\/ allow for Selenocysteine (U)\r\n\treturn \/^[ACDEFGHIKLMNPQRSTUVWY\\s]+$\/i.test(fasta);\r\n}<\/pre>\n<p>Let me know, by comments below, if you spot a no-no. \u00a0Please link to this post if you find use for it.<\/p>\n<p>p.s. I already noticed that this only validates <strong>one<\/strong> sequence. \u00a0This is because this function is taken out of one of our web servers, <a title=\"Memoir, membrane protein modelling\" href=\"http:\/\/opig.stats.ox.ac.uk\/webapps\/memoir\/php\/index.php\" target=\"_blank\">Memoir<\/a>, which specifically only requires one sequence. \u00a0If there is interested for multi sequence validation I will add it.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was more than a bit annoyed of not finding this out there in the interwebs, being a strong encourager of googling (or in Jamie&#8217;s case duck-duck-going) and re-use. So I proffer my very own fasta validation javascript function. \/* * Validates (true\/false) a single fasta sequence string * param fasta the string containing a [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","wikipediapreview_detectlinks":true,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29,14,15],"tags":[],"ppma_author":[483],"class_list":["post-409","post","type-post","status-publish","format-standard","hentry","category-code","category-howto","category-technical"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"authors":[{"term_id":483,"user_id":6,"is_guest":0,"slug":"jp","display_name":"JP Ebejer","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/0c2ee7f7a071e0ff6aebc09ddb6c7bdd90146efeb8dfac34f7724f0b04ceafe8?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/409","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/comments?post=409"}],"version-history":[{"count":5,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions"}],"predecessor-version":[{"id":413,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/posts\/409\/revisions\/413"}],"wp:attachment":[{"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/media?parent=409"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/categories?post=409"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/tags?post=409"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.blopig.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=409"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}