Skip to content
Snippets Groups Projects
Commit c751af74 authored by rlapar's avatar rlapar
Browse files

main exception handling

parent 493e3575
No related branches found
No related tags found
1 merge request!6Reengineering
......@@ -4,6 +4,8 @@ import sys
import os
import shutil
import click
from datetime import datetime
from subprocess import CalledProcessError
from Bio import SeqIO
......@@ -24,34 +26,39 @@ def cleanup():
@click.option('--input_fasta', '-i', required=True, type=str, help='Input fasta file.')
@click.option('--sketch_only', '-s', is_flag=True)
def main(input_fasta, sketch_only):
numberOfErrors = 0
startTime = datetime.now()
setup()
#RUN
sequences = list(SeqIO.parse(open(input_fasta), 'fasta'))
for sequence in sequences:
seqStartTime = datetime.now()
print('Processing {}...'.format(sequence.id), end='\r')
try:
if not os.path.exists('data/{}'.format(sequence.id)):
os.makedirs('data/{}'.format(sequence.id))
if not os.path.exists('data/{}/TE'.format(sequence.id)):
os.makedirs('data/{}/TE'.format(sequence.id))
print('Running Nester for {}...'.format(sequence.id))
if not sketch_only:
nester = Nester(sequence)
#for a in nester.nestedList:
# print(a)
# for b in a.features['domains']:
# print('--------------------')
# print(b)
# print('##########################')
sketch.createGFF(sequence.id, sequence.seq, nester.nestedList)
sketch.sketch(sequence.id)
seqEndTime = datetime.now()
print('Processing {}: done [{}]'.format(sequence.id, seqEndTime - seqStartTime))
except KeyboardInterrupt:
raise
#except:
# print('Unexpected error:', sys.exc_info()[0])
except CalledProcessError:
numberOfErrors += 1
print('Processing {}: SUBPROCESS ERROR'.format(sequence.id))
except:
numberOfErrors += 1
print('Processing {}: UNEXPECTED ERROR:'.format(sequence.id), sys.exc_info()[0])
cleanup()
endTime = datetime.now()
print('Total time: {}'.format(endTime - startTime))
print('Number of errors: {}'.format(numberOfErrors))
if __name__ == '__main__':
main()
\ No newline at end of file
import os
import subprocess
from Bio import SeqIO
......@@ -83,5 +84,8 @@ def createGFF(id, sequence, nestedList):
GFF.write([rec], out_handle)
def sketch(id):
process = subprocess.Popen([config.gt_sketch_path] + config.gt_sketch_args + ['data/{}/{}.png'.format(id, id)] + ['data/{}/{}.gff'.format(id, id)])
null = open(os.devnull, 'w')
process = subprocess.check_output([config.gt_sketch_path] + config.gt_sketch_args + ['data/{}/{}.png'.format(id, id)] + ['data/{}/{}.gff'.format(id, id)], stderr=null)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment