@@ -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+
761768def get_input_args ():
762769 parser = argparse .ArgumentParser ()
763770 chrom_group = parser .add_mutually_exclusive_group (required = True )
0 commit comments