Skip to content

Instantly share code, notes, and snippets.

@canimus
Created January 14, 2024 19:31
Show Gist options
  • Save canimus/ad579b15cb209fbd29e1510e4243a0ac to your computer and use it in GitHub Desktop.
Save canimus/ad579b15cb209fbd29e1510e4243a0ac to your computer and use it in GitHub Desktop.
Format genbank sequence
def format_sequence(sequence: str):
"""Format a DNA sequence as genbank file"""
counter = 1
print(f"{counter}".rjust(4, " "), end=" ")
for a,b in zip(range(0,len(sequence)+1, 10), range(10, len(sequence)+1, 10)):
print(sequence[a:b], end="")
if ((counter % 6) == 0) and (b < (len(sequence)-1)):
print("")
print(f'{((counter*10) + 1)}'.rjust(4, " "), end=" ")
else:
print(" ", end="")
counter += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment