Skip to content

Repository files navigation

CODE FREEZE:

PyGeno has long been limited due to it's backend. We are now ready to take it to the next level.

We are working on a major port of pyGeno to the open-source multi-modal database ArangoDB. PyGeno's code on both branches master and bloody is frozen until we are finished. No pull request will be merged until then, and we won't implement any new features.

pyGeno: A Python package for precision medicine and proteogenomics

depsydownloadsdownloads_monthdownloads_week

pyGeno's logo

pyGeno is (to our knowledge) the only tool available that will gladly build your specific genomes for you.

pyGeno is developed by Tariq Daouda at the Institute for Research in Immunology and Cancer (IRIC), its logo is the work of the freelance designer Sawssan Kaddoura. For the latest news about pyGeno, you can follow me on twitter @tariqdaouda.

Click here for The full documentation.

For the latest news about pyGeno, you can follow me on twitter @tariqdaouda.

Citing pyGeno:

Please cite this paper.

Installation:

It is recommended to install pyGeno within a virtual environement, to setup one you can use:

virtualenv ~/.pyGenoEnv
source~/.pyGenoEnv/bin/activate

pyGeno can be installed through pip:

pip install pyGeno #for the latest stable version

Or github, for the latest developments:

git clone https://github.com/tariqdaouda/pyGeno.git
cd pyGeno
python setup.py develop

A brief introduction

pyGeno is a personal bioinformatic database that runs directly into python, on your laptop and does not depend upon any REST API. pyGeno is here to make extracting data such as gene sequences a breeze, and is designed to be able cope with huge queries. The most exciting feature of pyGeno, is that it allows to work with seamlessly with both reference and Personalized Genomes.

Personalized Genomes, are custom genomes that you create by combining a reference genome, sets of polymorphisms and an optional filter. pyGeno will take care of applying the filter and inserting the polymorphisms at their right place, so you get direct access to the DNA and Protein sequences of your patients.

frompyGeno.Genomeimport*g=Genome(name="GRCh37.75")
prot=g.get(Protein, id='ENSP00000438917')[0]
#print the protein sequenceprintprot.sequence#print the protein's gene biotypeprintprot.gene.biotype#print protein's transcript sequenceprintprot.transcript.sequence#fancy queriesforexoning.get(Exon, {"CDS_start >": x1, "CDS_end <=" : x2, "chromosome.number" : "22"}) :
#print the exon's coding sequenceprintexon.CDS#print the exon's transcript sequenceprintexon.transcript.sequence#You can do the same for your subject specific genomes#by combining a reference genome with polymorphismsg=Genome(name="GRCh37.75", SNPs= ["STY21_RNA"], SNPFilter=MyFilter())

And if you ever get lost, there's an online help() function for each object type:

frompyGeno.Genomeimport*printExon.help()

Should output:

Available fields for Exon: CDS_start, end, chromosome, CDS_length, frame, number, CDS_end, start, genome, length, protein, gene, transcript, id, strand

Creating a Personalized Genome:

Personalized Genomes are a powerful feature that allow you to work on the specific genomes and proteomes of your patients. You can even mix several SNP sets together.

frompyGeno.GenomeimportGenome#the name of the snp set is defined inside the datawrap's manifest.ini filedummy=Genome(name='GRCh37.75', SNPs='dummySRY')
#you can also define a filter (ex: a quality filter) for the SNPsdummy=Genome(name='GRCh37.75', SNPs='dummySRY', SNPFilter=myFilter())
#and even mix several snp setsdummy=Genome(name='GRCh37.75', SNPs= ['dummySRY', 'anotherSet'], SNPFilter=myFilter())

Filtering SNPs:

pyGeno allows you to select the Polymorphisms that end up into the final sequences. It supports SNPs, Inserts and Deletions.

frompyGeno.SNPFilteringimportSNPFilter, SequenceSNPclassQMax_gt_filter(SNPFilter) :
def__init__(self, threshold) :
self.threshold=threshold#Here SNPs is a dictionary: SNPSet Name => polymorphism#This filter ignores deletions and insertions and#but applis all SNPsdeffilter(self, chromosome, **SNPs) :
sources= {}
alleles= []
forsnpSet, snpinSNPs.iteritems() :
pos=snp.startifsnp.alt[0] =='-' :
passelifsnp.ref[0] =='-' :
passelse :
sources[snpSet] =snpalleles.append(snp.alt) #if not an indel append the polymorphism#appends the refence allele to the lotrefAllele=chromosome.refSequence[pos]
alleles.append(refAllele)
sources['ref'] =refAllele#optional we keep a record of the polymorphisms that were used during the processreturnSequenceSNP(alleles, sources=sources)

The filter function can also be made more specific by using arguments that have the same names as the SNPSets

deffilter(self, chromosome, dummySRY=None) :
ifdummySRY.Qmax_gt>self.threshold :
#other possibilities of return are SequenceInsert(<bases>), SequenceDelete(<length>)returnSequenceSNP(dummySRY.alt)
returnNone#None means keep the reference allele

To apply the filter simply specify if while loading the genome.

persGenome=Genome(name='GRCh37.75_Y-Only', SNPs='dummySRY', SNPFilter=QMax_gt_filter(10))

To include several SNPSets use a list.

persGenome=Genome(name='GRCh37.75_Y-Only', SNPs= ['ARN_P1', 'ARN_P2'], SNPFilter=myFilter())

Getting an arbitrary sequence:

You can ask for any sequence of any chromosome:

chr12=myGenome.get(Chromosome, number="12")[0]
printchr12.sequence[x1:x2]
# for the reference sequenceprintchr12.refSequence[x1:x2]

Batteries included (bootstraping):

pyGeno's database is populated by importing datawraps. pyGeno comes with a few data wraps, to get the list you can use:

importpyGeno.bootstrapasBB.printDatawraps()
Available datawraps for boostraping
SNPs
~~~~|
|~~~:> Human_agnostic.dummySRY.tar.gz
|~~~:> Human.dummySRY_casava.tar.gz
|~~~:> dbSNP142_human_common_all.tar.gz
Genomes
~~~~~~~|
|~~~:> Human.GRCh37.75.tar.gz
|~~~:> Human.GRCh37.75_Y-Only.tar.gz
|~~~:> Human.GRCh38.78.tar.gz
|~~~:> Mouse.GRCm38.78.tar.gz

To get a list of remote datawraps that pyGeno can download for you, do:

B.printRemoteDatawraps()

Importing whole genomes is a demanding process that take more than an hour and requires (according to tests) at least 3GB of memory. Depending on your configuration, more might be required.

That being said importating a data wrap is a one time operation and once the importation is complete the datawrap can be discarded without consequences.

The bootstrap module also has some handy functions for importing built-in packages.

Some of them just for playing around with pyGeno (Fast importation and Small memory requirements):

importpyGeno.bootstrapasB#Imports only the Y chromosome from the human reference genome GRCh37.75#Very fast, requires even less memory. No download required.B.importGenome("Human.GRCh37.75_Y-Only.tar.gz")
#A dummy datawrap for humans SNPs and Indels in pyGeno's AgnosticSNP format.# This one has one SNP at the begining of the gene SRYB.importSNPs("Human.dummySRY_casava.tar.gz")

And for more Serious Work, the whole reference genome.

#Downloads the whole genome (205MB, sequences + annotations), may take an hour or more.B.importGenome("Human.GRCh38.78.tar.gz")

Importing a custom datawrap:

frompyGeno.importation.Genomesimport*importGenome('GRCh37.75.tar.gz')

To import a patient's specific polymorphisms

frompyGeno.importation.SNPsimport*importSNPs('patient1.tar.gz')

For a list of available datawraps available for download, please have a look here.

You can easily make your own datawraps with any tar.gz compressor. For more details on how datawraps are made you can check wiki or have a look inside the folder bootstrap_data.

Instanciating a genome:

frompyGeno.GenomeimportGenome#the name of the genome is defined inside the package's manifest.ini fileref=Genome(name='GRCh37.75')

Printing all the proteins of a gene:

frompyGeno.GenomeimportGenomefrompyGeno.GeneimportGenefrompyGeno.ProteinimportProtein

Or simply:

frompyGeno.Genomeimport*

then:

ref=Genome(name='GRCh37.75')
#get returns a list of elementsgene=ref.get(Gene, name='TPST2')[0]
forprotingene.get(Protein) :
printprot.sequence

Making queries, get() Vs iterGet():

iterGet is a faster version of get that returns an iterator instead of a list.

Making queries, syntax:

pyGeno's get function uses the expressivity of rabaDB.

These are all possible query formats:

ref.get(Gene, name="SRY")
ref.get(Gene, { "name like" : "HLA"})
chr12.get(Exon, { "start >=" : 12000, "end <" : 12300 })
ref.get(Transcript, { "gene.name" : 'SRY' })

Creating indexes to speed up queries:

frompyGeno.GeneimportGene#creating an index on gene names if it does not already existGene.ensureGlobalIndex('name')
#removing the indexGene.dropIndex('name')

Find in sequences:

Internally pyGeno uses a binary representation for nucleotides and amino acids to deal with polymorphisms. For example,both "AGC" and "ATG" will match the following sequence "...AT/GCCG...".

#returns the position of the first occurencetranscript.find("AT/GCCG")
#returns the positions of all occurencestranscript.findAll("AT/GCCG")
#similarly, you can also dotranscript.findIncDNA("AT/GCCG")
transcript.findAllIncDNA("AT/GCCG")
transcript.findInUTR3("AT/GCCG")
transcript.findAllInUTR3("AT/GCCG")
transcript.findInUTR5("AT/GCCG")
transcript.findAllInUTR5("AT/GCCG")
#same for proteinsprotein.find("DEV/RDEM")
protein.findAll("DEV/RDEM")
#and for exonsexon.find("AT/GCCG")
exon.findAll("AT/GCCG")
exon.findInCDS("AT/GCCG")
exon.findAllInCDS("AT/GCCG")
#...

Progress Bar:

frompyGeno.tools.ProgressBarimportProgressBarpg=ProgressBar(nbEpochs=155)
foriinrange(155) :
pg.update(label='%d'%i) # or simply p.update()pg.close()

Releases

Packages

Used by

Contributors

Languages