Skip to content

Instantly share code, notes, and snippets.

@hopeseekr
Created May 3, 2020 20:25
Show Gist options
  • Save hopeseekr/d89467e91b3696deac623a3c603c26ab to your computer and use it in GitHub Desktop.
Save hopeseekr/d89467e91b3696deac623a3c603c26ab to your computer and use it in GitHub Desktop.
Splits long DNA strings into sequences and then counts the stop codons.
<?php
$DNA = file($argv[1]);
$splitDNA = str_split($DNA[1], 3);
$stopCodons = [
'TAG',
'TAA',
'TGA',
];
$codonCounts = array_count_values($splitDNA);
foreach ($stopCodons as $stopCodon) {
echo "$stopCodon: " . ($codonCounts[$stopCodon] ?? 0) . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment