From 3e83196d256cc0f2a47c27ebedf0323fc288947b Mon Sep 17 00:00:00 2001 From: Chinmaya Narayana <58813915+chinmayaNK22@users.noreply.github.com> Date: Wed, 9 Nov 2022 18:08:00 +0530 Subject: [PATCH] Create read_fasta_file_v2.py --- read_fasta_file_v2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 read_fasta_file_v2.py diff --git a/read_fasta_file_v2.py b/read_fasta_file_v2.py new file mode 100644 index 0000000..f72e802 --- /dev/null +++ b/read_fasta_file_v2.py @@ -0,0 +1,31 @@ +from itertools import groupby + + +class readfasta(object): + + def __init__(self, infile): + self.infile = infile + + def read(self): + file_format = {'fasta':1, 'faa':2, 'fna':3} + if self.infile.split('.')[-1].lower() in file_format: + read_file = open(self.infile) + faiter = (x[1] for x in groupby(read_file, lambda line: line[0] == ">")) + for header in faiter: + header = next(header)[1:].strip() + seq = "".join(s.strip() for s in next(faiter)) + yield header, seq + + else: + filetype = self.infile.split('.')[-1] + raise Exception(f'Can only read FASTA file format with file extensions fasta, faa or fna') + + +class decoy_pro(object): + def __init__(self, protein): + self.protein = protein + + def Reverse(self): + pro = [self.protein[p] for p in range(len(self.protein)) if p+1 == len(self.protein)] + [self.protein[p] for p in range(len(self.protein)) if p+1 != len(self.protein)] + pro.reverse() + return ''.join(pro)