Commit 2926c20e authored by Danfox Davies's avatar Danfox Davies

Merge branch 'foul-fortune-feline' into 'master'

Foul fortune feline

See merge request !8
parents ffc1c947 9323609f
.DS_Store
.idea/*
**/__pycache__
# map_aic
#
# Module for mapping an arbitrary piece of mRNA to a predetermined list of
# weights. Also contains utilities for editing said predetermined list.
#
# Author: Lucianna Osucha (email:lucianna@vulpinedesigns.com)
**Contents:**
-*mapAIC.py* Main end user program
-*modMappings.py* Utility interface. Feed files to this modify the preset mappings
-*example_input.txt* An example of input, ready to feed to modMappings.py
*modMappings.py* comes complete with a helper utility. Use -h or --help to access it.
# mapAIC.py
#
# Reads weights from a file, maps them to codons in arbitrary strings of mRNA
#
# Author: Lucianna Osucha (email:lucianna@vulpinedesigns.com)
import sys
sys.path.append('../')
from util.mRNA import *
from struct import *
try:
m_weights = open("codonWeights.dat", "rb")
except OSError as e:
print("[!!FATAL!!] Error opening \"codonWeights.dat\"\n"
, file=sys.stderr)
raise
def mapAICs(rna:mRNA) -> mRNA:
for i in rna.code:
m_weights.seek(i * 8)
rna.baseWeights.append(unpack('<d', m_weights.read(8)))
return rna
# modMappings.py
#
# Utility for editing the codonWeights.dat file
#
# Author: Lucianna Osucha (email:lucianna@vulpinedesigns.com)
import sys
import argparse
from struct import *
from util.mRNA import *
try:
m_file = open('codonWeights.dat','r+b')
except OSError as e:
print("\"codonWeights.dat\" not found!\n"
+ "Constructing new file...", file=sys.stderr)
m_file = open('codonWeights.dat','x+b')
m_file.write(bytearray(pack('<' + 'd'*64, *([0.0]*64))))
parser = argparse.ArgumentParser(description="A helper utility for populating "
+ "the \"codonWeights.dat\" file"
, epilog="File Formatting Example:\n\nAUG 1000\nCUG 140\nAUC 15.3"
, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('infile', nargs='*', type=argparse.FileType('r')
, help="Read weights stored in a file and update \"codonWeights.dat\" with "
+ "the new data. Leave empty to print out currently stored data")
args = parser.parse_args()
if args.infile == []:
for i in range(64):
print(codonIndex(i) + " ", *unpack('<d', m_file.read(8)))
sys.exit()
for n_file in args.infile:
while True:
codon = n_file.read(4)
if codon == None or codon == "":
break
m_file.seek(indexCodon(codon) * 8)
m_file.write(bytearray(pack('<d', float(n_file.readline()))))
# AminoAcids.py
#
# Utils for dealing with Amino Acid Chains
#
# Authored by: Lucianna Osucha (email:lucianna@vulpinedesigns.com)
from mRNA import *
const aminoAlphabet:str = '*RHKDESTNQCUGPAVILMFYW'
const 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]
class AminoAcidChain:
def __init__(self, seq:list[int]):
self.sequence:list[int] = seq
self.length:int = len(seq)
self.postTranslationalModificationSites:list = []
def __init__(self, seq:str):
self.__init__([aminoAlphabet.index(i) for i in seq])
# util
#
# Collection of utilities for general use in the INITIATOR_SET module of the
# GUESS
#
# Authorship:
# -Lucianna Osucha (lucianna@vulpinedesigns.com)
**Contents:**
-*mRNA.py* Utils for dealing with strands of mRNA
-*AminoAcids.py* Utils for dealing with chains of Amino Acids
# mRNA.py
#
# A representation of mRNA strand with a slew of metadata and utils for working
# with it
#
# Authored by: Lucianna Osucha (email:lucianna@vulpinedesigns.com)
bases = ['A', 'U', 'G', 'C'];
def codonIndex(index:int) -> str:
result = bases[int(index/16)]
result += bases[int((index/4))%4]
result += bases[index%4]
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])
return result
class mRNA :
def __init__(self, cd:list[int], og:str, pal:int):
self.code:list[int] = 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
class Iterable(mRNA) :
def __init__(self, parent:mRNA, start:int, stop:int):
self.parent:mRNA = parent
self.loc:int = start - 3
if stop <= start or stop > len(parent.code):
self.stop = len(parent.code)
else:
self.stop:int = stop
def __iter__(self):
return self
def next(self):
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