Posts

Showing posts with the label Reading Multiple Sequences

Extracting Multiple FASTA Sequences using PHP

Image
This is a simple tutorial which explains how to safely extract multiple sequences from a FASTA file using PHP script. I have used four functions to perform different tasks: read_fas_file() - to check invalid file, fas_check() - to check FASTA file format, get_seq() - to retrieve sequence and sequence name pairs, and fas_get() - to extract and display multiple FASTA file formatted sequences. The full source code and multiple protein sequences in FASTA file format used in this tutorial is given below. Source Code function read_fas_file($x) { // Check for Empty File if (!file_exists($x)) { print "File Not Exist!!"; exit(); } else { $fh = fopen($x, 'r'); if (filesize($x) == 0) { print "File is Empty!!"; fclose($fh); exit(); } else { $f = fread($fh, filesize($x)); fclose($fh); return $f; } } } function fas_check($x) { // Check FASTA File Format $gt = substr($x, 0, 1); if ($gt != ">") { print "Not F...