Skip to main content

Code to work with Genbank files

Project description

genbank

Python code to work with Genbank files

This repo contains several classes to help work with Genbank files

The flow goes:

File -> Locus -> Feature

To use:

from genbank.file import File

file = File('infile.gbk')
for locus in file:
	print(name)
	for feature in locus:
		print(feature)

You can also build a Locus object from the ground up:

from genbank.locus import Locus
locus = Locus('test', 'actgactgatcgtagctagc')
# then add a feature by parsing text of a genbank feature
locus.read_feature('  CDS  1..10')
# or add manually by specifing the type,strand,location
locus.add_feature('CDS',+1,[['10','20']])
locus.write()

which gives:

LOCUS       test                      20 bp
FEATURES             Location/Qualifiers
     CDS             1..10
     CDS             10..20
ORIGIN
        1 actgactgat cgtagctagc
//

This package also allows you to perform various conversions on a given genome file:

$ genbank.py tests/phiX174.gbk -f tabular
'phiX174'	'CDS'	(('100', '627'),)	{'gene': "G"}
'phiX174'	'CDS'	(('636', '1622'),)	{'gene': "H"}
'phiX174'	'CDS'	(('1659', '3227'),)	{'gene': "A"}
'phiX174'	'CDS'	(('2780', '3142'),)	{'gene': "B"}
'phiX174'	'CDS'	(('3142', '3312'),)	{'gene': "K"}

$ genbank.py tests/phiX174.gbk -f fasta
>phiX174
gtgtgaggttataacgccgaagcggtaaaaattttaatttttgccgctgagggg
ttgaccaagcgaagcgcggtaggttttctgcttaggagtttaatcatgtttcag

$ genbank.py tests/phiX174.gbk -f fna
>phiX174_CDS_[100..627] [gene="G"]
atgtttcagacttttatttctcgccataattcaaactttttttctgataag
>phiX174_CDS_[636..1622] [gene="H"]
atgtttggtgctattgctggcggtattgcttctgctcttgctggtggcgcc
>phiX174_CDS_[1659..3227]

$ genbank.py tests/phiX174.gbk -f faa
>phiX174_CDS_[100..627] [gene="G"]
MFQTFISRHNSNFFSDKLVLTSVTPASSAPVLQTPKATSSTLYFDSLTVNA
>phiX174_CDS_[636..1622] [gene="H"]
MFGAIAGGIASALAGGAMSKLFGGGQKAASGGIQGDVLATDNNTVGMGDAG
>phiX174_CDS_[1659..3227] [gene="A"]

$ genbank.py tests/phiX174.gbk -f coverage
phiX174	0.965

Print out the features of the given key:tag

$ genbank.py tests/phiX174.gbk -k CDS:gene > labels.tsv

Change the H of the second gene to something more informative: (ideally you will have columns from other sources, like excel)

perl -pi -e 's/H/Minor spike/' labels.tsv

Now edit all the features of the given key:tag with the updated labels:

$ genbank.py tests/phiX174.gbk -e CDS:gene < labels.tsv | head
LOCUS       phiX174                 5386 bp    DNA      PHG
FEATURES             Location/Qualifiers
     source          1..5386
     rep_origin      13..56
     CDS             100..627
                     /gene="G"
     CDS             636..1622
                     /gene="Minor spike"
     CDS             1659..3227

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

genbank-0.81.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

genbank-0.81-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file genbank-0.81.tar.gz.

File metadata

  • Download URL: genbank-0.81.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for genbank-0.81.tar.gz
Algorithm Hash digest
SHA256 070ee488a20cf4f5f76be2e7d4d7774fe78586ee2b7c27b486ced029b3d10144
MD5 5e787e88bc33336e6e7f3ee4ec34b6e9
BLAKE2b-256 6324066e2d438ad8a859d5cd808a39eced01a025152237fe1613817aabc90cb1

See more details on using hashes here.

File details

Details for the file genbank-0.81-py3-none-any.whl.

File metadata

  • Download URL: genbank-0.81-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for genbank-0.81-py3-none-any.whl
Algorithm Hash digest
SHA256 e0c0a050eace4bc4f32d72edc93d95e68fb6037975ae923c631ba3bec2b10ec3
MD5 19f41250ce440bfd3aa514c12b25d978
BLAKE2b-256 bfbee5fa1faa58f008195ea246680c0dccc01edb0244c480f171a05d1fd49745

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page