<?php
function sortString($string)
{
$type_chars = str_split($string);
sort($type_chars);
return implode($type_chars);
}
function getValue($map, $input)
{
$key = implode(',', array_map('sortString', $input));
return $map[$key] ?? null;
}
function sortMap($map)
{
return array_reduce(array_keys($map), function ($sorted_map, $types) use ($map) {
$sorted_types = preg_replace_callback('/[A-Z]{2}/', function ($matches) {
return sortString($matches[0]);
}, $types);
$sorted_map[$sorted_types] = $map[$types];
return $sorted_map;
}, []);
}
$map = sortMap([
'CC,GG,AA,CC' => 'high',
'TT,GA,TT,CG' => 'medium',
'CT,AG,TT,GG' => 'low',
]);
echo getValue($map, ['CC', 'GG', 'AA', 'CC']) . "\n"; // high
echo getValue($map, ['TT', 'AG', 'TT', 'CG']) . "\n"; // medium
echo getValue($map, ['TT', 'GA', 'TT', 'GC']) . "\n"; // medium
echo getValue($map, ['CT', 'AG', 'TT', 'GG']) . "\n"; // low
- Output for 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- high
medium
medium
low
preferences:
139.24 ms | 407 KiB | 5 Q