Commit 2128b85b authored by Lucianna's avatar Lucianna

Basic conversion of mRNA to AminoAcidChain (WIP)

Cleaned some things up, fixed some bugs
Refactor AminoAcids.py to AminoChain.py
parent 9323609f
# AminoAcids.py
#
# Utils for dealing with Amino Acid Chains
#
# Authored by: Lucianna Osucha (lucianna@vulpinedesigns.com)
from mRNA import *
metadataTypes:list = ['originMRNA', 'locFlags']
aminoAlphabet:list = ['*', 'R', 'H', 'K', 'D', 'E', 'S', 'T', 'N', 'Q', 'C', 'U', 'G'
, 'P', 'A', 'V', 'I', 'L', 'M', 'F', 'Y', 'W']
aminoCodons:list = [3, 8, 3, 8, 16, 16, 18, 16, 1, 6, 1, 6, 7, 7, 7, 7, 0, 20
, 0, 20, 17, 19, 17, 19, 0, 10, 21, 10, 6, 6, 6, 6, 5, 4, 5, 4, 15, 15, 15
, 15, 12, 12, 12, 12, 14, 14, 14, 14, 9, 2, 9, 2, 17, 17, 17, 17, 1, 1, 1, 1
, 13, 13, 13, 13]
def indexAminoChain(seq:str) -> list:
result:list = []
for i in seq:
result.append(aminoAlphabet.index(i))
return result
def deindexAminoChain(seq:list) -> str:
result = '';
for i in seq:
result += aminoAlphabet[i]
return result;
def convertRNA(seq:list) -> list:
result:list = []
for i in range(0, len(seq), 3):
result.append(aminoCodons[seq[i]])
return result
class AminoAcidChain:
def __init__(self, seq):
self.metadata:list = []
if isinstance(seq, str):
seq = indexAminoChain(seq)
if isinstance(seq, list):
self.sequence:list[int] = seq
else:
raise TypeError("'seq' must be of type 'str' or 'list'")
self.length:int = len(seq)
@classmethod
def fromMRNA(cls, seq):
if isinstance(seq, mRNA):
seq = seq.code
if isinstance(seq, str):
seq = indexRNA(seq)
if isinstance(seq, list):
print(seq)
return cls(convertRNA(seq))
else:
raise TypeError("'seq' must be of type 'mRNA', 'str', or 'list'")
def __str__(self) -> str:
return deindexAminoChain(self.sequence)
......@@ -2,8 +2,8 @@
#
# A representation of mRNA strand with a slew of metadata and utils for working
# with it
#
# Authored by: Lucianna Osucha (email:lucianna@vulpinedesigns.com)
#
# Authored by: Lucianna Osucha (lucianna@vulpinedesigns.com)
......@@ -19,60 +19,63 @@ def codonIndex(index:int) -> str:
def rnaIndex(code:list) -> str:
result = ''
for i in range (0, len(code), 3):
result = result + codonIndex(code[i])
i = len(code) % 3
result = result[:-i] + codonIndex(code[-1])
return result
def indexCodon(codon:str) -> int:
result = bases.index(codon[0]) * 16
result += bases.index(codon[1]) * 4
result += bases.index(codon[2])
return result
def indexRNA(code:str) -> list:
result = []
for i in range(len(code-2)):
result.append(indexCodon(code[i:i+3])
for i in range(len(code) - 2):
result.append(indexCodon(code[i:i+3]))
return result
class mRNA :
def __init__(self, cd:list[int], og:str, pal:int):
self.code:list[int] = cd
class mRNA:
def __init__(self, cd, og:str, pal:int):
if isinstance(cd, str):
cd = indexRNA(cd)
if not isinstance(cd, list):
raise TypeError("'cd' must be of type 'str' or 'list'")
self.code:list = cd
self.originGene:str = og
self.polyALength:int = pal
self.baseWeights:list[float] = []
self.kozakStrengths:list[float] = []
self.leakyScanStrengths:list[float] = []
self.localisationSequences:list[tuple] = []
self.hairpins:list[tuple] = []
self.IREs:list[tuple] = []
self.uORFs:list[tuple] = []
self.adjustedWeights:list[float] = []
self.processedBy:list[str] = []
def __init__(self, cd:str, og:str, pal:int):
self.__init__(indexRNA(cd), og, pal)
def __string__(self) -> str:
result = ''
for i in range (0, len(self.code), 3):
result = result + codonIndex(self.code[i])
i = len(self.code) % 3
result = result[:-i] + codonIndex(self.code[-1])
return result
def __str__(self) -> str:
return rnaIndex(self.code)
class Iterable(mRNA) :
......@@ -94,6 +97,6 @@ class Iterable(mRNA) :
self.loc += 3
if self.loc >= self.stop:
raise StopIteration
value = self.parent.code[self.loc:(self.loc + 3)]
return value
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment