Skip to content

Commit

Permalink
fasta formatter script and executable
Browse files Browse the repository at this point in the history
  • Loading branch information
olgatsiouri1996 committed Nov 16, 2021
1 parent 17a8a48 commit ebebd62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ python scripts that can be easily transformed to gui programs for wet lab scient
14. tab to fasta GUI: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5703366.svg)](https://doi.org/10.5281/zenodo.5703366)
15. single-fastas to tabular GUI: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5672075.svg)](https://doi.org/10.5281/zenodo.5672075)
16. tabular file to single-fastas GUI: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5652249.svg)](https://doi.org/10.5281/zenodo.5652249)
17. fasta formatter GUI: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5703665.svg)](https://doi.org/10.5281/zenodo.5703665)
24 changes: 24 additions & 0 deletions fasta_manipulation/fasta_formatter_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# python3
from gooey import *
from Bio import SeqIO
import sys
# input parameters
@Gooey(required_cols=2, program_name= 'fasta formatter', header_bg_color= '#DCDCDC', terminal_font_color= '#DCDCDC', terminal_panel_color= '#DCDCDC')
def main():
ap = GooeyParser(description="changes the width of sequences line in a FASTA file")
ap.add_argument("-in", "--input", required=True, widget="FileChooser", help="input fasta file")
ap.add_argument("-out", "--output", required=True, widget="FileSaver", help="output fasta file")
ap.add_argument("-width", "--width", required=False, type=int, default=80, help="number of characters per line. Default 80")
args = vars(ap.parse_args())
# main
# create function to split the input sequence based on a specific number of characters
def split_every_width(s): return [s[i:i+args['width']] for i in range(0,len(s),args['width'])]
# export to a new fasta file
sys.stdout = open(args['output'], 'a')
for record in SeqIO.parse(args['input'],'fasta'):
print(">"+record.id)
print('\n'.join(split_every_width(str(record.seq)))) # add characters in new line after the number of characters surpasses the input width
sys.stdout.close()

if __name__ == '__main__':
main()

0 comments on commit ebebd62

Please sign in to comment.