Skip to content

Instantly share code, notes, and snippets.

@bbarry
Created November 22, 2010 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbarry/710816 to your computer and use it in GitHub Desktop.
Save bbarry/710816 to your computer and use it in GitHub Desktop.
hits
import MetagenomeDB as mdb
names = ['check1', 'check2', 'check3']
def run():
c = mdb.Collection.find_one({"name": "NL10_1002_vRNA:contigs-strict"})
output=[]
for sequence in c.list_sequences():
if (not "alignments" in sequence):
continue
for hit in sequence["alignments"]:
checks= [
("rdrp" in hit["hit"]["description"].lower()) and ("blastx" in hit["run"]["algorithm"]["name"].lower()),
("virus" in hit["hit"]["description"].lower()) and ("blastx" in hit["run"]["algorithm"]["name"].lower()) and 0.02 > (hit["score"]["e_value"]),
("rdrp" in hit["hit"]["description"].lower()) and ("rpstblastn" in hit["run"]["algorithm"]["name"].lower())
]
names = ['check1', 'check2', 'check3']
l=[names[v] for v in range(0,3) if checks[v]]
m=[names[x] for x in range(0,3) if checks[x] else '']
score=len(l)
if score>0:
output.append({
'name': sequence.get_property("name"),
'score': score,
'checks_passed': ' '.join(l),
'e_value': hit["score"]["e_value"],
'checks_as_list': m
})
return output
items = run()
print len(item)
output=[]
for item in items:
output.append(item['name'])
output.append(':')
output.append(str(item['score']))
output.append(':')
output.append(str(item['e_value']))
output.append(':')
output.append(':'.join(item['checks_as_list']))
output.append("\n")
print ''.join(output)
@bbolduc
Copy link

bbolduc commented Nov 22, 2010

import MetagenomeDB as mdb
c = mdb.Collection.find_one({"name": "NL10_1006_vRNA:contigs-strict"})
for sequence in c.list_sequences():
if (not "alignments" in sequence):
continue
for hit in sequence["alignments"]:
if ("rdrp" in hit["hit"]["description"].lower()) and ("blastx" in hit["run"]["algorithm"]["name"].lower()):
print "RdRp hit in BlastX " + sequence.get_property("name") + " " + str(hit["score"]["e_value"])
if ("virus" in hit["hit"]["description"].lower()) and ("blastx" in hit["run"]["algorithm"]["name"].lower()) and 0.02 > (hit["score"]["e_value"]):
print "Significant BlastX Virus Hit " + sequence.get_property("name") + " " + str(hit["score"]["e_value"])
if ("rdrp" in hit["hit"]["description"].lower()) and ("rpstblastn" in hit["run"]["algorithm"]["name"].lower()):
print "Conserved Domain RdRp Hit " + sequence.get_property("name") + " " + str(hit["score"]["e_value"])

@bbolduc
Copy link

bbolduc commented Nov 22, 2010

from cStringIO import StringIO

def Score(l):
return len([item for item in l if item])

import MetagenomeDB as mdb
c = mdb.Collection.find_one({"name": "NL10_1006_vRNA:contigs-strict"})
output=[]
for sequence in c.list_sequences():
if (not "alignments" in sequence):
continue
for hit in sequence["alignments"]:
checks=[("rdrp" in hit["hit"]["description"].lower()) and ("blastx" in hit["run"]["algorithm"]["name"].lower()),
("virus" in hit["hit"]["description"].lower()) and ("blastx" in hit["run"]["algorithm"]["name"].lower()) and 0.02 > (hit["score"]["e_value"]),
("rdrp" in hit["hit"]["description"].lower()) and ("rpstblastn" in hit["run"]["algorithm"]["name"].lower())]
if Score(checks)>1:
output.append('')
print ''.join(output)

@bbarry
Copy link
Author

bbarry commented Nov 22, 2010

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment