diff --git a/README.md b/README.md index 1cd6d3c..4266864 100644 --- a/README.md +++ b/README.md @@ -18,3 +18,4 @@ python scripts that can be easily transformed to gui programs for wet lab scient 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) +18. chain pdb to fasta GUI: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5706468.svg)](https://doi.org/10.5281/zenodo.5706468) diff --git a/pdb_corner/chain_pdb_to_fasta_gui.py b/pdb_corner/chain_pdb_to_fasta_gui.py index 2f1d22a..1457081 100644 --- a/pdb_corner/chain_pdb_to_fasta_gui.py +++ b/pdb_corner/chain_pdb_to_fasta_gui.py @@ -1,29 +1,31 @@ # python3 from gooey import * from Bio.PDB import * -import sys +import os +from Bio import SeqIO +from Bio.Seq import Seq +from Bio.SeqRecord import SeqRecord # input parameters -@Gooey(required_cols=5, program_name='pdb chain to fasta', header_bg_color= '#DCDCDC', terminal_font_color= '#DCDCDC', terminal_panel_color= '#DCDCDC') +@Gooey(required_cols=2, program_name='pdb chain to fasta', header_bg_color= '#DCDCDC', terminal_font_color= '#DCDCDC', terminal_panel_color= '#DCDCDC') def main(): ap = GooeyParser(description="subsets a pdb file by selecting the model and chain and convert the output to fasta format") ap.add_argument("-pdb", "--pdb", required=True, widget='FileChooser', help="input pdb file") - ap.add_argument("-model", "--model", required=True, help="model from pdb file to select(integer)") + ap.add_argument("-model", "--model",default=0, required=False, help="model from pdb file to select(integer). Default is 0(1 model only)") ap.add_argument("-chain", "--chain", required=True, help="chain from pdb file to select") - ap.add_argument("-id", "--id", required=True, help="pdb id of the protein structure") - ap.add_argument("-fasta", "--fasta", required=True, widget='FileSaver', help="output fasta file") args = vars(ap.parse_args()) - #main - def seq_from_pdb(structure): - ppb = PPBuilder() - for pp in ppb.build_peptides(structure): - print(">"+args['id']+"_"+args['chain'],pp.get_sequence(), sep="\n") - +# main +# select chain parser = PDBParser() s = parser.get_structure("name", args['pdb']) fill = s[int(args['model'])][args['chain']] - sys.stdout = open(args['fasta'], 'a') - seq_from_pdb(fill) - sys.stdout.close() - +# retrieve the pdb id of the input file + filename = os.path.split(args['pdb'])[1] + pdb_id = filename.split(".")[0] +# export to fasta + ppb = PPBuilder() + for pp in ppb.build_peptides(fill): + record = SeqRecord(Seq(str(pp.get_sequence())),id="".join([str(pdb_id),"_",str(args['chain'])]),description="") + SeqIO.write(record, "".join([str(pdb_id),"_",str(args['chain']),".fasta"]), "fasta") + if __name__ == '__main__': main()