Package: genbank
genbankPython code to work with Genbank filesThis repo contains several classes to help work with Genbank filesThe flow goes:File -> Locus -> FeatureTo use:fromgenbank.fileimportFilefile=File('infile.gbk')forlocusinfile:print(name)forfeatureinlocus:print(feature)You can also build a Locus object from the ground up:fromgenbank.locusimportLocuslocus=Locus('test','actgactgatcgtagctagc')# then add a feature by parsing text of a genbank featurelocus.read_feature('  CDS  1..10')# or add manually by specifing the type,strand,locationlocus.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.pytests/phiX174.gbk-ftabular'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.pytests/phiX174.gbk-ffasta
>phiX174
gtgtgaggttataacgccgaagcggtaaaaattttaatttttgccgctgagggg
ttgaccaagcgaagcgcggtaggttttctgcttaggagtttaatcatgtttcag

$genbank.pytests/phiX174.gbk-ffna
>phiX174_CDS_[100..627][gene="G"]atgtttcagacttttatttctcgccataattcaaactttttttctgataag
>phiX174_CDS_[636..1622][gene="H"]atgtttggtgctattgctggcggtattgcttctgctcttgctggtggcgcc
>phiX174_CDS_[1659..3227]$genbank.pytests/phiX174.gbk-ffaa
>phiX174_CDS_[100..627][gene="G"]MFQTFISRHNSNFFSDKLVLTSVTPASSAPVLQTPKATSSTLYFDSLTVNA
>phiX174_CDS_[636..1622][gene="H"]MFGAIAGGIASALAGGAMSKLFGGGQKAASGGIQGDVLATDNNTVGMGDAG
>phiX174_CDS_[1659..3227][gene="A"]$genbank.pytests/phiX174.gbk-fcoverage
phiX1741.1168You can alsoslicethe locus to a specified range and only the nucleotides and
features that occur within the slice are kept. The command to take the first two
hundred bases of the phiX174 genome is shown below.$genbank.pytests/phiX174.gbk--slice1..200
LOCUSphiX174200bpDNAPHG
DEFINITIONphiX174
FEATURESLocation/Qualifiersrep_origin13..56CDS100..>200/gene="G"/note="merged"ORIGIN1gtgtgaggttataacgccgaagcggtaaaaattttaatttttgccgctgaggggttgacc61aagcgaagcgcggtaggttttctgcttaggagtttaatcatgtttcagacttttatttct121cgccataattcaaactttttttctgataagctggttctcacttctgttactccagcttct181tcggcacctgttttacagac
//Theslicearguement can be paired with all the other output format options:$genbank.pytests/phiX174.gbk--slice1..200-fcoverage0.51You can also easily edit features by running multiple commands.Print out the features of a specifiedkey:taginto a file$ genbank.py tests/phiX174.gbk -k CDS:gene > labels.tsvChange 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.tsvEdit all the features of a specifiedkey:tagwith 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