Skip to content

Commit 7735a96

Browse files
Merge pull request #37 from YuWei-CH/Update-length-using-function
Update length using function
2 parents 2ce3c1c + 1c263aa commit 7735a96

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

reform.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def create_new_gff(new_gff_name, ref_gff, in_gff_lines, position, down_position,
514514
if line.startswith("##sequence-region") and line_elements[1] == chrom_id:
515515
## Edit the length of the chromosome
516516
original_length = int(line_elements[3])
517-
new_length = original_length - (down_position - position) + new_seq_length
517+
new_length = calculate_new_length(original_length, position, down_position, new_seq_length)
518518
line = line.replace(str(original_length), str(new_length))
519519
gff_out.write(line)
520520
else:
@@ -555,7 +555,7 @@ def create_new_gff(new_gff_name, ref_gff, in_gff_lines, position, down_position,
555555
# "chromosome" or "region")
556556
elif gff_feat_type in ['chromosome', 'region']:
557557
original_length = gff_feat_end
558-
new_length = original_length - (down_position - position) + new_seq_length
558+
new_length = calculate_new_length(original_length, position, down_position, new_seq_length)
559559
line = line.replace(str(original_length), str(new_length))
560560
gff_out.write(line)
561561

@@ -757,7 +757,14 @@ def rename_id(line):
757757
else:
758758
print(f"This feature will not be renamed because it does not have an ID/gene_id attribute:\n{line}")
759759
return attributes
760-
760+
761+
def calculate_new_length(original_length, position, down_position, new_seq_length):
762+
"""
763+
Calculate the new chromosome/region length after a modification.
764+
Returns: The new calculated length
765+
"""
766+
return original_length - (down_position - position) + new_seq_length
767+
761768
def get_input_args():
762769
parser = argparse.ArgumentParser()
763770
chrom_group = parser.add_mutually_exclusive_group(required=True)

0 commit comments

Comments
 (0)