Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial commit of genbank script #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
CHANGELOG
=========

Version 1.4.0
-------------

* added genbank downloader script

Version 1.3.2
-------------

Expand Down
45 changes: 45 additions & 0 deletions bio_bits/genbank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'''
Usage:
genbank <infile>
'''
from Bio import SeqIO
import dateparser
import sys
from docopt import docopt

def rec_qualifier(rec, key):
for f in rec.features:
if f.qualifiers:
if 'collection_date' in f.qualifiers:
return f.qualifiers[key]

def fix_date(d):
date = dateparser.parse(d)
return date.strftime('%Y-%m-%d')

def rec_to_fasta(rec):
raw_collection_date = rec_qualifier(rec, 'collection_date')[0]
country = rec_qualifier(rec, 'country')[0]
date = dateparser.parse(raw_collection_date)
date = date.strftime('%Y-%m-%d')
rec.description = "|{}|{}".format(country, date)
return rec

# acc = rec.name
#header = "{}|{}|{}".format(acc, country, date)
#seq = str(rec.seq)
#return rec.format("fasta")
def run(infile):
with open(infile) as input:
gb = SeqIO.parse(input, 'genbank')
results = map(rec_to_fasta, gb)
SeqIO.write(results, sys.stdout, 'fasta')

def main():
raw_args = docopt(__doc__, version='Version 1.0')
run(raw_args['<infile>'])
sys.exit(0)


# ['17-Feb-2010']
# rec = degen.id_to_record("KJ627355")
1 change: 1 addition & 0 deletions requirements-pip.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
argparse
docopt
dateparser
future
schema
sh
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'degen = bio_bits.degen:main',
'plot_muts = bio_bits.plot_muts:main',
'fasta = bio_bits.fasta:main',
'genbank = bio_bits.genbank:main',
#'sequence_concat = bio_bits.sequence_concat:main',
#'sequence_files_concat = bio_bits.sequence_files_concat:main',
#'sequence_split = bio_bits_old.sequence_split:main',
Expand Down