def run(args):
	EcsEntry.objects.all().delete()
	parser = EcsFileParser(args[1])

	try:
		inserter = BulkInserter(EcsEntry)
		while True:
			entries = parser.next_ecs_entry()
			if not entries: break
			for entry in entries:
				inserter.save(entry)
		inserter.close()
	except Exception:
		inserter.rollback()
		raise
def run(args):
	try:
		parser = geovision.text_to_db.sample_parser.SamplefileParser(args[1])
	except IOError:
		print "Unable to open file", args[1]
		sys.exit(1);
	if ImportedData.objects.filter(type='sample', data=parser.sample).exists():
		print("Warning: Not importing sample %s because it already exists" % parser.sample)
		sys.exit(1)
	try:
		inserter = BulkInserter(Read)
		read_entry = parser.next_read()
		while read_entry is not None:
			inserter.save(read_entry)
			read_entry = parser.next_read()
		inserter.close()
		ImportedData.objects.create(type='sample', data=parser.sample)
	except Exception as e:
		inserter.rollback()
		raise 
Example #3
0
def run(args):
	try:
		parser = geovision.text_to_db.db_parser.DbfileParser(args[1], args[2])
	except IOError:
		print("Unable to open file", args[1])
		sys.exit(1);
	if ImportedData.objects.filter(type='dbentry', data=parser.source).exists():
		print("Warning: Not importing database %s because it already exists" % args[2])
		sys.exit(1)
	try:
		inserter = BulkInserter(DbEntry)
		db_entry = parser.next_db_entry()
		while db_entry is not None:
			inserter.save(db_entry)
			db_entry = parser.next_db_entry()
		inserter.close()
		ImportedData.objects.create(type='dbentry', data=parser.source)
	except Exception as e:
		inserter.rollback()
		raise
Example #4
0
		(read_id, db_seq_id, pident, length, mismatch, gapopen, qstart, qend, sstart, send, error_value, bitscore, read_seq, db_seq) = line.split(None)
		if db_name == 'uniprot':
			db_seq_id = db_seq_id.split('|')[1]
		id = inserter.get_id()
		inserter.save(dict_from_kwargs(read_id=read_id, database_name=db_name, sample=sample_name, db_entry_id=db_seq_id, bitscore=bitscore, error_value=error_value))
		extra_inserter.save(dict_from_kwargs(blast_id=id, pident=pident, length=length, mismatch=mismatch, gapopen=gapopen, qstart=qstart, qend=qend, sstart=sstart, send=send, read_seq=read_seq, db_seq=db_seq))
	inserter.close()
	extra_inserter.close()
	
if __name__ == '__main__':
	import sys
	filename = sys.argv[1]
	(sample_name, db_name, rest) = os.path.basename(filename).split('.')
	blast_name = sample_name + '.' + db_name
	if ImportedData.objects.filter(type='blast', data=blast_name).exists():
		print("Not importing blast %s because it already exists" % blast_name)
		sys.exit(1)
	if not ImportedData.objects.filter(type='sample', data=sample_name).exists():
		print("Not importing blast %s because sample %s doesn't exist" % (blast_name, sample_name)) 
		sys.exit(1)
	if not ImportedData.objects.filter(type='dbentry', data=db_name).exists():
		print("Not importing blast %s because database %s doesn't exist" % (blast_name, db_name))
		sys.exit(1)
	try:
		create_blast(db_name, sample_name, filename)
		ImportedData.objects.create(type='blast', data=blast_name)
	except Exception as e:
		inserter.rollback()
		extra_inserter.rollback()
		raise