-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge single-fasta and multi-fasta scripts and executables to 1
- Loading branch information
1 parent
6ca130c
commit 9dedc9c
Showing
8 changed files
with
110 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# python3 | ||
import os | ||
from gooey import * | ||
from Bio import SeqIO | ||
# input parameters | ||
@Gooey(required_cols=0, program_name='trim a multi-fasta file or multiple single-fasta files', header_bg_color= '#DCDCDC', terminal_font_color= '#DCDCDC', terminal_panel_color= '#DCDCDC') | ||
def main(): | ||
ap = GooeyParser() | ||
ap.add_argument("-in", "--input", required=False ,widget='FileChooser', help="input fasta file") | ||
ap.add_argument("-start", "--start", required=False, default=1, type=int, help="region to start writing the fasta file(default 1)") | ||
ap.add_argument("-stop", "--stop", required=False, type=int, help="region to stop writing the fasta file(it can be both a positive and a negative number)") | ||
ap.add_argument("-dir", "--directory", required=False, type=str, widget='DirChooser', help="directory to search for fasta files") | ||
ap.add_argument("-pro", "--program", required=False,default=1, type=int, help="program to choose 1) add both start and stop location 2) the stop location will be that of the sequence length. Default is 1") | ||
ap.add_argument("-type", "--type", required=False,default=1, type=int, help="type of fasta to import 1) 1 multi-fasta file 2) many single-fasta files. Default is 1") | ||
ap.add_argument("-out", "--output", required=False, widget='FileSaver', help="output fasta file") | ||
args = vars(ap.parse_args()) | ||
# main | ||
# create function to trim fasta records | ||
def fastatrim(fastarec,fastaseq): | ||
# choose program | ||
if args['program'] == 1: | ||
# fix the index for start parameter | ||
if args['start'] > 0: | ||
seq_start = args['start'] -1 | ||
else: | ||
print("-start parameter must be a positive integer") | ||
exit(1) | ||
# add end parameter | ||
seq_end = args['stop'] | ||
else: | ||
# fix the index for start parameter | ||
if args['start'] > 0: | ||
seq_start = args['start'] -1 | ||
else: | ||
print("-start parameter must be a positive integer") | ||
exit(1) | ||
# add end parameter according to program 2 | ||
args['stop'] = len(fastaseq) | ||
seq_end = args['stop'] | ||
# subset each fasta record | ||
return fastarec[seq_start:seq_end] | ||
# choose fasta type to import | ||
if args['type'] == 1: | ||
# setup an empty list | ||
sequences = [] | ||
# iterate for each record | ||
for record in SeqIO.parse(args['input'], "fasta"): | ||
# add this record to the list | ||
sequences.append(fastatrim(record,record.seq)) | ||
# export to fasta | ||
SeqIO.write(sequences, args['output'], "fasta") | ||
else: | ||
# import each fasta file from the working directory | ||
for filename in sorted(os.listdir(os.chdir(args['directory']))): | ||
if filename.endswith(".fa") or filename.endswith(".fasta"): | ||
# read each file, trim and create SeqRecord to export | ||
record = SeqIO.read(filename, "fasta") | ||
sequence = fastatrim(record,record.seq) | ||
# export to fasta | ||
SeqIO.write(sequence, "".join([filename.split(".")[0],"_","trimmed",".fasta"]), "fasta") | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.