Pandas ExtensionDtypes and ExtensionArray for working with genomics data
Project description
Pandas ExtensionDtypes and ExtensionArray for working with genomics data
Quickstart
Variant
objects holds information about a particular variant:
from pandas_genomics.scalars import Variant
variant = Variant('12', 112161652, id='rs12462', ref='A', alt=['C', 'T'])
print(variant)
rs12462[chr=12;pos=112161652;ref=A;alt=C,T]
Genotype
objects are associated with a particular Variant
:
gt = variant.make_genotype("A", "C")
print(gt)
A/C
The GenotypeArray
stores genotypes with an associated variant and has useful methods:
from pandas_genomics.scalars import Variant
from pandas_genomics.arrays import GenotypeArray
variant = Variant('12', 112161652, id='rs12462', ref='A', alt=['C'])
gt_array = GenotypeArray([variant.make_genotype_from_str(s) for s in ["C/C", "A/C", "A/A"]])
print(gt_array)
<GenotypeArray>
[Genotype(variant=rs12462[chr=12;pos=112161652;ref=A;alt=C], allele1=1, allele2=1),
Genotype(variant=rs12462[chr=12;pos=112161652;ref=A;alt=C], allele1=0, allele2=1),
Genotype(variant=rs12462[chr=12;pos=112161652;ref=A;alt=C], allele1=0, allele2=0)]
Length: 3, dtype: genotype[12; 112161652; rs12462; A; C]
print(gt_array.astype(str))
['C/C' 'A/C' 'A/A']
print(gt_array.encode_dominant())
<IntegerArray>
[1, 1, 0]
Length: 3, dtype: UInt8
There is also a SeriesAccessor named genotype
import pandas as pd
print(pd.Series(gt_array).genotype.encode_codominant())
0 Hom
1 Het
2 Ref
Name: rs12462_C, dtype: category
Categories (3, object): ['Ref' < 'Het' < 'Hom']
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pandas-genomics-0.3.1.tar.gz
(17.4 kB
view hashes)
Built Distribution
Close
Hashes for pandas_genomics-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 517a8af16064cea16268188f4978a66dcb72681a280f42599600fbba851e1cfe |
|
MD5 | affefafa8de00be368668ac32c52b72e |
|
BLAKE2b-256 | 0bc2b69b27d2d42a9044631992839158746460ecbc58fa5064d0f06f9319c2be |