Skip to content

Commit

Permalink
refactored _is_inversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jeicher committed Mar 9, 2017
1 parent 03e63c4 commit 24bb00d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions seq2simulate/diversity.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,13 @@ def _simulate_inversions(sequences, freq=0.3, max_length=200, min_length=15):
while new_stops_introduced:
ins_start = random.randrange(0, len(seq)-min_length)
ins_length = random.randint(min_length, min(max_length, len(seq)-ins_start))
new_sequence = seq[0:ins_start] + seq[ins_start:ins_start + ins_length][::-1] + seq[ins_start + ins_length:]
inverted_sequence = seq[ins_start:ins_start + ins_length][::-1]
new_sequence = seq[0:ins_start] + inverted_sequence + seq[ins_start + ins_length:]
if _get_n_stop_codons(new_sequence) <= _get_n_stop_codons(seq):
new_stops_introduced = False
sequences[i] = new_sequence
seq_diffs.append([ins_start, ins_start + ins_length])
seq_diffs.append([ins_start, ins_start + ins_length, inverted_sequence])
print(seq_diffs)
else:
seq_diffs.append([])
return sequences, seq_diffs
Expand Down
6 changes: 3 additions & 3 deletions seq2simulate/run_make_proviral_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _make_mutation_data_files(sequences, working_dir, hypermutation_rate=3):
'insertion': [diversity._simulate_insertions, {'freq': 0, 'no_frameshifts': True}],
'frameshift': [diversity._simulate_frameshifts, {'freq': 0}],
'stopcodon': [diversity._simulate_stop_codons, {'freq': 0}],
'inversion': [diversity._simulate_inversions, {'freq': 0}],
'inversion': [diversity._simulate_inversions, {'freq': 1}],
}

for i_mutation, mutation_type in enumerate(mutation_types):
Expand Down Expand Up @@ -332,8 +332,8 @@ def _is_stopcodon(sam_line, seq_diffs):

def _is_inversion(sam_line, seq_diffs):
if seq_diffs:
if seq_diffs[0] <= sam_line['read_start'] and seq_diffs[1] > sam_line['read_start'] \
or sam_line['read_start'] <= seq_diffs[0] <= sam_line['read_end']:
if _covers_index(seq_diffs[0], seq_diffs[1], sam_line['read_start']) \
or _covers_index(sam_line['read_start'], sam_line['read_end'], seq_diffs[0]):
return True
return False

Expand Down

0 comments on commit 24bb00d

Please sign in to comment.