From b82fd5beba26e9f055cc3d075cac5a25451effae Mon Sep 17 00:00:00 2001 From: Ram RS Date: Fri, 23 Aug 2013 14:35:26 -0400 Subject: [PATCH 1/3] Modified namedb.py and annotate-seqs.py to work with files supplied via command line to annotate-seqs.py mouse.namedb, mouse.namedb.fullname and mouse.protein.faa were hardcoded into namedb.py. Now, it picks up from sys.argv[4] and sys.argv[5], where sys.argv is supplied to annotate-seqs.py Possible regression bugs if namedb.py is used by scripts other than annotate-seqs.py that use a different command line argument pattern --- annotate-seqs.py | 10 ++++++---- namedb.py | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/annotate-seqs.py b/annotate-seqs.py index 848ff03..3361459 100644 --- a/annotate-seqs.py +++ b/annotate-seqs.py @@ -16,6 +16,8 @@ def main(): parser.add_argument('transcripts') parser.add_argument('ortho') parser.add_argument('homol') + parser.add_argument('namedb') + parser.add_argument('dbFa') parser.add_argument('-z', '--no-ncbi', action='store_false', dest='ncbi', default='True') args = parser.parse_args() @@ -37,7 +39,7 @@ def main(): o = ortho.get(name) if o: - annot = namedb.mouse_names.get(transform_name(o, args.ncbi)) + annot = namedb.data_names.get(transform_name(o, args.ncbi)) tr_dict[tr] = ('ortho', annot) else: if tr in tr_dict and tr_dict[tr][0] == 'ortho': @@ -52,7 +54,7 @@ def main(): h, score = h[0] score = round(float(score) / float(len(record.sequence)) * 100) - annot = namedb.mouse_names[transform_name(h, args.ncbi)] + annot = namedb.data_names[transform_name(h, args.ncbi)] if score > oldscore: tr_dict[tr] = (oldscore, annot) @@ -76,7 +78,7 @@ def main(): o = ortho.get(name) if o: - annot = namedb.mouse_names.get(transform_name(o, args.ncbi)) + annot = namedb.data_names.get(transform_name(o, args.ncbi)) annot = "ortho:" + annot annot_ortho_count += 1 else: @@ -85,7 +87,7 @@ def main(): if h: h, score = h[0] score = round(float(score) / float(len(record.sequence)) * 100) - annot = namedb.mouse_names[transform_name(h, args.ncbi)] + annot = namedb.data_names[transform_name(h, args.ncbi)] annot = "h=%d%% => " % score + annot annot += " " annot_homol_count += 1 diff --git a/namedb.py b/namedb.py index 4b84d33..9cb1131 100644 --- a/namedb.py +++ b/namedb.py @@ -1,6 +1,7 @@ import cPickle import screed -mouse_names = cPickle.load(open('mouse.namedb')) -mouse_fullname = cPickle.load(open('mouse.namedb.fullname')) -mouse_seqs = screed.ScreedDB('mouse.protein.faa') +data_names = cPickle.load(open(sys.argv[4])) +fullname = "%s.fullname" % sys.argv[4] +data_fullname = cPickle.load(open(fullname)) +data_seqs = screed.ScreedDB(sys.argv[5]) From cdb86755aefc13dd198e62b8c6d913917d5ba027 Mon Sep 17 00:00:00 2001 From: Ramakrishnan RS Date: Sun, 25 Aug 2013 17:16:04 -0400 Subject: [PATCH 2/3] Modified annotate-seqs, make-namedb and namedb to work on custom seq file and constant namedb files make-namedb changed to pickle into constant names.db and fullnames.db files, and pickle sequence filename into names.db. namedb.py modified to unpickle correspondingly. Lines expecting extra CMD line args in annotate-seqs removed. --- annotate-seqs.py | 2 -- make-namedb.py | 9 +++++---- namedb.py | 9 +++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/annotate-seqs.py b/annotate-seqs.py index 3361459..f7f6e28 100644 --- a/annotate-seqs.py +++ b/annotate-seqs.py @@ -16,8 +16,6 @@ def main(): parser.add_argument('transcripts') parser.add_argument('ortho') parser.add_argument('homol') - parser.add_argument('namedb') - parser.add_argument('dbFa') parser.add_argument('-z', '--no-ncbi', action='store_false', dest='ncbi', default='True') args = parser.parse_args() diff --git a/make-namedb.py b/make-namedb.py index d6eb5f0..4e33699 100644 --- a/make-namedb.py +++ b/make-namedb.py @@ -4,7 +4,8 @@ import screed import sys -outfile = sys.argv[2] +# the name-db +outfile = "names.db" d = {} e = {} @@ -17,7 +18,7 @@ e[ident] = record.name fp = open(outfile, 'w') -dump(d, fp) +dump(dict(seqs=sys.argv[1],names=d), fp) -fp = open(outfile + '.fullname', 'w') -dump(e, fp) +fp = open('fullnames.db', 'w') +dump(e, fp) \ No newline at end of file diff --git a/namedb.py b/namedb.py index 9cb1131..deb7706 100644 --- a/namedb.py +++ b/namedb.py @@ -1,7 +1,8 @@ import cPickle import screed -data_names = cPickle.load(open(sys.argv[4])) -fullname = "%s.fullname" % sys.argv[4] -data_fullname = cPickle.load(open(fullname)) -data_seqs = screed.ScreedDB(sys.argv[5]) +data = cPickle.load('names.db') + +data_names = data.get('names',[]) +data_fullname = cPickle.load(open('fullnames.db')) +data_seqs = screed.ScreedDB(data.get('seqs'),[]) From eb177a443ed7851641bff28e10f049852f76e5b7 Mon Sep 17 00:00:00 2001 From: Ram RS Date: Sun, 25 Aug 2013 22:59:04 -0400 Subject: [PATCH 3/3] Pickling no longer uses dict. var seqFile stores seq file name dict() used in previous commit has been removed, sequential calls to dump() and load() are used instead. A variable 'seqFile' id used to store sequence file name from CMD line args. --- .gitignore | 1 + make-namedb.py | 6 ++++-- namedb.py | 6 ++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index cc6f93b..a01cc10 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ mouse.protein.faa.psq petMar_lamp0.fasta petMar_lamp3.fasta petMar_mrna.lamp3.orig.fasta.gz +/.project diff --git a/make-namedb.py b/make-namedb.py index 4e33699..2f37254 100644 --- a/make-namedb.py +++ b/make-namedb.py @@ -6,10 +6,11 @@ # the name-db outfile = "names.db" +seqFile = sys.argv[1] d = {} e = {} -for record in screed.open(sys.argv[1]): +for record in screed.open(seqFile): if record.name.startswith('gi|'): ident = record.name.split('|')[3] else: @@ -18,7 +19,8 @@ e[ident] = record.name fp = open(outfile, 'w') -dump(dict(seqs=sys.argv[1],names=d), fp) +dump(seqFile, fp) +dump(d,fp) fp = open('fullnames.db', 'w') dump(e, fp) \ No newline at end of file diff --git a/namedb.py b/namedb.py index deb7706..f5ec688 100644 --- a/namedb.py +++ b/namedb.py @@ -1,8 +1,6 @@ import cPickle import screed -data = cPickle.load('names.db') - -data_names = data.get('names',[]) +data_names = cPickle.load('names.db') data_fullname = cPickle.load(open('fullnames.db')) -data_seqs = screed.ScreedDB(data.get('seqs'),[]) +data_seqs = screed.ScreedDB(cPickle.load('names.db'))