Skip to content

Commit

Permalink
Merge pull request #40 from NAL-i5K/gff3_fix_phase
Browse files Browse the repository at this point in the history
fix_phase - Set the initial phase as 0, if phase missing
  • Loading branch information
mpoelchau authored Jun 18, 2018
2 parents 7f96313 + f536f3d commit a1f3db5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions gff3tool/lib/gff3/gff3.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def check_phase(self, initial_phase):
if cds_list[0]['phase'] != 0:
self.add_line_error(cds_list[0], {'message': '{0:s} {1:d}, should be {2:d}'.format(ERROR_INFO['Ema0006'], cds_list[0]['phase'], 0), 'error_type': 'PHASE', 'eCode': 'Ema0006'})
if type(cds_list[0]['phase']) != int:
logger.warning('[Phase] Program failed. \n\t\t- Line {0:s}: {1:s}'.format(str(cds_list[0]['line_index']+1), cds_list[0]['line_raw']))
logger.warning('[Phase] check_phase failed. \n\t\t- Line {0:s}: {1:s}'.format(str(cds_list[0]['line_index']+1), cds_list[0]['line_raw']))
continue
strand = strand_set[0]
if strand not in plus_minus:
Expand All @@ -309,13 +309,13 @@ def check_phase(self, initial_phase):
else:
phase = sorted_cds_list[0]['phase']
if type(phase) != int:
logger.warning('[Phase] Program failed. \n\t\t- Line {0:s}: {1:s}'.format(str(sorted_cds_list[0]['line_index']+1), sorted_cds_list[0]['line_raw']))
logger.warning('[Phase] check_phase failed. \n\t\t- Line {0:s}: {1:s}'.format(str(sorted_cds_list[0]['line_index']+1), sorted_cds_list[0]['line_raw']))
for line in sorted_cds_list:
if line['phase'] != phase:
try:
self.add_line_error(line, {'message': 'Wrong phase {0:d}, should be {1:d}'.format(line['phase'], phase), 'error_type': 'PHASE', 'eCode': 'Ema0006'})
except:
logger.warning('[Phase] Program failed. \n\t\t- Line {0:s}: {1:s}'.format(str(line['line_index']+1), line['line_raw']))
logger.warning('[Phase] check_phase failed. \n\t\t- Line {0:s}: {1:s}'.format(str(line['line_index']+1), line['line_raw']))
try:
phase = (3 - ((line['end'] - line['start'] + 1 - phase) % 3)) % 3
except:
Expand Down
8 changes: 7 additions & 1 deletion gff3tool/lib/gff3_fix/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def fix_phase(gff3, error_list, line_num_dict, logger):
Esf0027 : Phase is required for all CDS features
"""
#valid_CDS_phase = set([0,1,2])
valid_phase = set((0, 1, 2))
for error in error_list:
for line_num in error:
if gff3.lines[line_num-1]['line_status'] != 'removed':
Expand All @@ -420,7 +421,12 @@ def fix_phase(gff3, error_list, line_num_dict, logger):
if 'Ema0006' in line_num_dict[sorted_CDS_list[0]['line_index']+1]:
phase = map(int,re.findall(r'\d',line_num_dict[sorted_CDS_list[0]['line_index']+1]['Ema0006']))[1]
else:
phase = sorted_CDS_list[0]['line_index']['phase']
try:
phase = sorted_CDS_list[0]['phase']
if phase not in valid_phase:
phase = 0
except ValueError:
phase = 0
gff3.lines[sorted_CDS_list[0]['line_index']]['phase'] = phase

else:
Expand Down

0 comments on commit a1f3db5

Please sign in to comment.