Skip to content

Instantly share code, notes, and snippets.

@arupgsh
Last active June 3, 2019 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arupgsh/2679cbdd2d1cd8175511afad59375b66 to your computer and use it in GitHub Desktop.
Save arupgsh/2679cbdd2d1cd8175511afad59375b66 to your computer and use it in GitHub Desktop.
# PHP function to display protein sequence in Uniprot like format
# Author Arup Ghosh
# Use $len = 60
function processSeq($str,$len){
$arr = str_split($str,$len);
$i=1;
// The code will be improved in future revisions
foreach($arr as $bit){
$k10=str_split($bit,10);
//var_dump($k10[0].$k10[1].$k10[2]);
$d1 = strlen($k10[0])*$i++;
$d2 = strlen($k10[1])*$i++;
$d3 = strlen($k10[2])*$i++;
$d4 = strlen($k10[3])*$i++;
$d5 = strlen($k10[4])*$i++;
$d6 = strlen($k10[5])*$i++;
// Avoid displaying blocks with no sequence and wrong counts when block length is <10
if($d2 == 0 || strlen($k10[1]) < 10){
$d2 = "";
};
if($d3 == 0 || strlen($k10[2]) < 10){
$d3 = "";
};
if($d4 == 0 || strlen($k10[3]) < 10){
$d4 = "";
};
if($d5 == 0 || strlen($k10[4]) < 10){
$d5 = "";
};
if($d6 == 0 || strlen($k10[5]) < 10){
$d6 = "";
};
// Calculate no of space will be required for the correct alignment of numbers
$l1 = str_repeat(" ",10-strlen($d1));
$l2 = str_repeat(" ",10-strlen($d2));
$l3 = str_repeat(" ",10-strlen($d3));
$l4 = str_repeat(" ",10-strlen($d4));
$l5 = str_repeat(" ",10-strlen($d5));
$l6 = str_repeat(" ",10-strlen($d6));
// Separate blocks for numbers and sequences
$loc = $l1.$d1." ".$l2.$d2." ".$l3.$d3." ".$l4.$d4." ".$l5.$d5." ".$l6.$d6." <br>";
$seq = $k10[0]." ".$k10[1]." ".$k10[2]." ".$k10[3]." ".$k10[4]." ".$k10[5]." <br>";
$dat[] = $loc.$seq;
};
$out="<pre>".implode("",$dat)."</pre>";;
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment