-
Notifications
You must be signed in to change notification settings - Fork 14
Using py‐ard in Python
py-ard
can be used in a program to reduce/expand HLA GL String representation. If pyard discovers an invalid Allele, it'll throw an Invalid Exception, not silently return an empty result.
Import pyard
package.
import pyard
Initialize ARD
object with a version of IMGT HLA database
import pyard
ard = pyard.init('3510')
When processing a large numbers of typings, it's helpful to have a cache of previously calculated reductions to make similar typings reduce faster. The cache size of pre-computed reductions can be changed from the default of 1,000 by setting cache_size
argument. This increases the memory footprint but will significantly increase the processing times for large number of reductions.
import pyard
max_cache_size = 1_000_000
ard = pyard.init('3510', cache_size=max_cache_size)
By default, the IPD-IMGT/HLA data is stored locally in $TMPDIR/pyard
. This may be removed when your computer restarts. You can specify a different, more permanent directory for the cached data.
import pyard.ard
ard = pyard.init('3510', data_dir='/tmp/py-ard')
As MAC data changes frequently, you can choose to refresh the MAC code for current IMGT HLA database version.
ard.refresh_mac_codes()
The default initialization is to use the latest version of IPD-IMGT/HLA database.
import pyard
ard = pyard.init()
You can check the current version of IPD-IMGT/HLA database.
ard.get_db_version()
Note: Previous to version of 1.0.0 release of py-ard
, there was redux
and redux_gl
methods on ard
. They have been consolidated so that redux
handles both GL Strings and individual alleles.
Reduce a single locus HLA Typing by specifying the allele/MAC/XX code and the reduction method to redux
method.
allele = "A*01:01:01"
ard.redux(allele, 'G')
# >>> 'A*01:01:01G'
ard.redux(allele, 'lg')
# >>> 'A*01:01g'
ard.redux(allele, 'lgx')
# >>> 'A*01:01'
Reduce an ambiguous GL String
# Reduce GL String
#
ard.redux("A*01:01/A*01:01N+A*02:AB^B*07:02+B*07:AB", "G")
# 'B*07:02:01G+B*07:02:01G^A*01:01:01G+A*02:01:01G/A*02:02'
You can also reduce serology based typings.
ard.redux('B14', 'lg')
# >>> 'B*14:01g/B*14:02g/B*14:03g/B*14:04g/B*14:05g/B*14:06g/B*14:08g/B*14:09g/B*14:10g/B*14:11g/B*14:12g/B*14:13g/B*14:14g/B*14:15g/B*14:16g/B*14:17g/B*14:18g/B*14:19g/B*14:20g/B*14:21g/B*14:22g/B*14:23g/B*14:24g/B*14:25g/B*14:26g/B*14:27g/B*14:28g/B*14:29g/B*14:30g/B*14:31g/B*14:32g/B*14:33g/B*14:34g/B*14:35g/B*14:36g/B*14:37g/B*14:38g/B*14:39g/B*14:40g/B*14:42g/B*14:43g/B*14:44g/B*14:45g/B*14:46g/B*14:47g/B*14:48g/B*14:49g/B*14:50g/B*14:51g/B*14:52g/B*14:53g/B*14:54g/B*14:55g/B*14:56g/B*14:57g/B*14:58g/B*14:59g/B*14:60g/B*14:62g/B*14:63g/B*14:65g/B*14:66g/B*14:68g/B*14:70Qg/B*14:71g/B*14:73g/B*14:74g/B*14:75g/B*14:77g/B*14:82g/B*14:83g/B*14:86g/B*14:87g/B*14:88g/B*14:90g/B*14:93g/B*14:94g/B*14:95g/B*14:96g/B*14:97g/B*14:99g/B*14:102g'