-
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.
- Loading branch information
1 parent
e65d71b
commit 3e83196
Showing
1 changed file
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |