Package: hlagenie
HLAGeniePython package for dealing with HLA sequence dataHeavily inspired by and dependent on the fantasticpyARDpackage. TheHLAGeniepackage strives to streamline and standardize the bulk handling of HLA sequence data and provide functions to simplify matching analysis.Table of ContentsInstallationInstall from PyPIInstall from sourceUsing HLAGenieUsinghlageniefrom PythonInitializehlagenieAccessing sequence dictionaries for HLA allelesRetrieve amino acid or nucleotide position from mature protein sequenceRetrieve amino acid substring from mature protein sequenceRetrieve epitope from mature protein sequenceCheck if two alleles have a mismatch at a given positionCount the number of amino acid mismatches at a position between donor and recipientCount the number of amino acid mismatches between donor and recipient at a given position given the allelesGet the antigen recognition domain sequence of an alleleGet the extracellular domain sequence of an alleleUsinghlageniefrom the command lineRetrieval of specific amino acid positionsRetrieval of ARD sequenceRetrieval of XRD sequenceRetrieval of mature protein sequenceChecking if positions are mismatched between two allelesCounting mismatches between donor and recipient given two sets of allelesFeature requestsContributingInstallationInstall from PyPIpip install hlagenieInstall from sourcepython3 -m venv venv
source venv/bin/activate
python setup.py installUsing HLAGenieUsinghlageniefrom Pythonhlagenieis intended to simplify the handling of HLA sequence data.InitializehlagenieImporthlageniepackageimporthlagenieInitializeGENIEobject with a version of the IMGT/HLA database.importhlageniegenie=hlagenie.init("3510")The default behavior is to use ungapped sequences for HLA alleles. If you would prefer the alleles to maintain the gaps that exist in the sequence alignment, passungap = Falseto theinitfunction.importhlageniegenie=hlagenie.init("3510",ungap=False)The first time an object is instantiated with a given IMGT/HLA database version, the package will download the appropriate MSF files from the IMGT/HLA GitHub repository and create a SQLite database in the/tmpfolder.Accessing sequence dictionaries for HLA allelesTheGENIEobject contains dictionaries of amino acid and nucleotide sequences for each HLA allele. The keys for the dictionaries are the HLA allele names. The values are the genetic sequences.All of the keys are two-field alleles given the shared protein sequence of these alleles.genie.seqs# mature protein sequencesgenie.full_seqs# full protein sequencesgenie.nuc_seqs# full nucleotide sequencesRetrieve amino acid or nucleotide position from mature protein sequenceTo get a given amino acid (or nucleotide) position from a given HLA allele, you can use thegetAAorgetNucfunctions. These functions are 1-indexed to match standard IMGT/HLA database nomenclature.For this and following functions, if a three- or four-field allele name is passed, a call is made topy-ardto reduce to the two-field level.genie.getAA("A*01:01",1)# returns "G"genie.getNuc("A*01:01",1)# returns "A"Retrieve amino acid substring from mature protein sequenceTo get a given amino acid substring from a given HLA allele, you can use thegetPeptidefunction. This function is 1-indexed as well and is inclusive of the start and end positions.genie.getPeptide("A*01:01",1,10)# returns "GSHSMRYFFT"Retrieve epitope from mature protein sequenceIf you pass an allele name and a list of positions to thegetEpitopefunction,hlageniewill return a formatted epitope string.genie.getEpitope("A*01:01",[1,2,3,4,5])# returns "1G_2S_3H_4S_5M"Check if two alleles have a mismatch at a given positionIf you pass two allele names and a position to theisPositionMismatchedfunction,hlageniewill return a boolean indicating whether or not the two alleles have a mismatch at that position.genie.isPositionMismatched("A*01:01","A*01:02",1)# returns False (the amino acid is the same at position 1 for both alleles)Count the number of amino acid mismatches at a position between donor and recipientThecountAAMismatchesfunction takes as input four amino acids, two from the donor and two from the recipient (in order). The function returns the number of mismatches between the donor and recipient at that position.This uses the logic that if a recipient has the donor's amino acid as either of their two amino acids, it is not a mismatch.genie.countAAMismatches("A","G","G","G")# returns 1Count the number of amino acid mismatches between donor and recipient at a given position given the allelesThecountAAMismatchesAllelefunction takes as input four alleles and an amino acid position. The input order is: Donor Allele 1, Donor Allele 2, Recipient Allele 1, Recipient Allele 2, amino acid position. The function returns the number of mismatches between the donor and recipient at that position, adjusting for donor homozygosity.genie.countAAMismatchesAllele("A*02:01","A*02:01","A*01:01","A*01:01",44)# returns 1Get the antigen recognition domain sequence of an alleleThegetARDfunction takes as input an allele name and returns the antigen recognition domain sequence of that allele.genie.getARD("A*01:01")Get the extracellular domain sequence of an alleleThegetXRDfunction takes as input an allele name and returns the extracellular domain sequence of that allele.genie.getXRD("A*01:01")Usinghlageniefrom the command lineSome command-line functions are now available.Retrieval of specific amino acid positionsRetrieval of ARD sequenceRetrieval of XRD sequenceRetrieval of mature protein sequenceNote that the gapped sequences can be retrieved for any of the following by passing the--gappedflag.Retrieval of specific amino acid positionsCallinghlageniefrom the command line with an allele name and space-delimited list of positions will allow you to retrieve the amino acid at those positions.hlagenie-a"A*01:01"-p12345# returns 1G_2S_3H_4S_5MRetrieval of ARD sequenceCallinghlageniefrom the command line with an allele name and the--ardflag will allow you to retrieve the ARD sequence of that allele.hlagenie-a"A*01:01"--ardRetrieval of XRD sequenceCallinghlageniefrom the command line with an allele name and the--xrdflag will allow you to retrieve the XRD sequence of that allele.hlagene-a"A*01:01"--xrdRetrieval of mature protein sequenceCallinghlageniefrom the command line with only an allele name will allow you to retrieve the mature protein sequence of that allele.hlagenie-a"A*01:01"Checking if positions are mismatched between two allelesCallinghlagenie-matchfrom the command line with two allele names and a position will allow you to check if the two alleles have a mismatch at that position. This is based on the mature protein sequence of the alleles. This uses the gapped sequences by default to best assess matching.hlagenie-match--allele1"A*01:01"--allele2"A*01:02"--positions1# returns MatchedSupplying a space-delimited list of positions will provide a count of mismatches between the alleles.hlagenie-match--allele1"A*01:01"--allele2"A*01:02"--positions12345# returns 0Callinghlagenie-matchfrom the command line with two allele names and no specified positions will allow you to count the total number of mismatches between the two alleles.hlagenie-match--allele1"A*01:01"--allele2"A*01:02"# returns 2Alternatively, you can use the--ardor--xrdflags to check for mismatches in the ARD or XRD sequences, respectively.hlagenie-match--allele1"A*01:01"--allele2"A*68:02"--ard# returns 23hlagenie-match--allele1"A*01:01"--allele2"A*68:02"--ard# returns 29Counting mismatches between donor and recipient given two sets of allelesCallinghlagenie-matchfrom the command line with a recipient genotype and a donor genotype and a set of positions will allow you to retrieve the number of mismatches between the donor and recipient at those positions. This is based on the mature protein sequence of the alleles. This uses the gapped sequences by default to best assess matching. This value is adjusted for donor homozygosity.hlagenie-match--recip-haplo"A*01:01+A*01:02"--donor-haplo"A*02:01+A*01:02"--positions12345# returns 0This can also be done with a single position.hlagenie-match--recip-geno"A*01:01+A*01:02"--donor-geno"A*02:01+A*01:02"--positions1# returns 0Supplying no positions gets the total number of mismatches between the donor and recipient, adjusted for donor homozygosity.hlagenie-match--recip-geno"A*01:01+A*01:02"--donor-geno"A*02:01+A*01:02"# returns 32Alternatively, you can use the--ardor--xrdflags to get the mismatches between the donor and recipient at the ARD or XRD level, respectively.hlagenie-match--recip-geno"A*01:01+A*01:02"--donor-geno"A*02:01+A*01:02"--ard# returns 24hlagenie-match--recip-geno"A*01:01+A*01:02"--donor-geno"A*02:01+A*01:02"--xrd# returns 29Feature requestsIf you have a feature request, please feel free to open a new discussion in theIdeaspage of the Discussions tab. Doing so allows for a more open discussion of the feature and allows others to chime in with their thoughts.ContributingContributions are welcome. Please feel free to open a pull request with your changes. If you are unsure of how to do this, please feel free to open a discussion in theQ&A. If you are interested in contributing but are unsure of where to start, please check out theIssuestab.Bug reporting is also welcome in theIssuestab. Please include as much information as possible, including the version ofhlagenieyou are using, the version of Python you are using, and the operating system you are using. If you are able to provide a minimal reproducible example, that would be very helpful.