Commit 6666dfbb authored by Lucianna's avatar Lucianna

map_aic V1.0

	-Bugfixed mapAIC.py
	-Added modMapping.py, a somewhat full-featured utility for editing the default weights of each codon
	-Updated README.MD with current project information
parent 635545d2
# 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 email: foul-fortune-feline@pm.me
**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
# Reads weights from a file, maps them to codons in arbitrary strings of mRNA
#
# Author email: foul-fortune-feline@pm.me
import sys
sys.path.append('../')
from problem_domain.mRNA import *
from struct import *
## codonWeighting.dat is a file filled with float data end to end
## from AAA - UUU - GGG - CCC
try:
weights = open("codonWeighting.dat", "rb")
except OSError as e:
print("Error opening \"codonWeighting.dat\"", file=sys.stderr)
raise
def indexBase(base:str) -> int:
if base[0] == 'A':
return 0
elif base[0] == 'U' or base[0] == 'T':
return 1
elif base[0] == 'G':
return 2
elif base[0] == 'C':
return 3
def indexCodon(codon:str) -> int: # Indexing elifant
result:int
if codon[0] == "A":
result = 0
elif codon[0] == "U":
result = 16
elif codon[0] == "G":
result = 32
elif codon[0] == "C":
result = 48
if codon[1] == "A":
result += 0
elif codon[1] == "U":
result += 4
elif codon[1] == "G":
result += 8
elif codon[1] == "C":
result += 12
if codon[2] == "A":
result += 0
elif codon[2] == "U":
result += 1
elif codon[2] == "G":
result += 2
elif codon[2] == "C":
result += 3
def baseIndex(index:int) -> str:
if index == 0:
return 'A'
elif index == 1:
return 'U'
elif index == 2:
return 'G'
elif index == 3:
return 'C'
def codonIndex(index:int) -> str:
result = baseIndex(int(index/16))
result += baseIndex(int((index/4))%4)
result += baseIndex(index%4)
return result
def indexCodon(codon:str) -> int:
result = indexBase(codon[0]) * 16
result += indexBase(codon[1]) * 4
result += indexBase(codon[2])
return result
def mapAICs(rna:mRNA) -> mRNA:
for i in range(len(rna.code)):
index = indexCodon(rna.code[i])
rna.baseWeights[i] = weights[index*400]
try:
m_weights = open("codonWeights.dat", "rb")
except OSError as e:
print("[!!FATAL!!] Error opening \"codonWeights.dat\"\n"
, file=sys.stderr)
raise
for i in range(0, len(rna.code) - 2):
index = indexCodon(rna.code[i:i+3])
m_weights.seek(index * 8)
rna.baseWeights.append(unpack('<d', m_weights.read(8)))
return mRNA
# modMappings.py
#
# Utility for editing the codonWeights.dat file
#
# Author Email: foul-fortune-feline@pm.me
import sys
import argparse
from struct 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))))
from mapAIC import *
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()))))
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