Commit c2cc764a authored by Lucianna Osucha's avatar Lucianna Osucha

Replace all tabs with double spaces and remove fasta/__pycache__

parent ce8d6d09
......@@ -8,9 +8,9 @@
**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
-*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.
......@@ -13,20 +13,20 @@ from struct import *
try:
m_weights = open(mypath + "/codonWeights.dat", "rb") # rb = read bytecode
m_weights = open(mypath + "/codonWeights.dat", "rb") # rb = read bytecode
except OSError as e:
print("[!!FATAL!!] Error opening \"codonWeights.dat\"\n"
, file=sys.stderr)
raise
print("[!!FATAL!!] Error opening \"codonWeights.dat\"\n"
, file=sys.stderr)
raise
def mapAICs(rna:mRNA.mRNA) -> mRNA.mRNA:
rna.metadata["baseWeights"] = {}
rna.metadata["baseWeights"] = {}
for i in rna.code:
# Go to the desired entry in datafile
m_weights.seek(i * 4)
rna.metadata["baseWeights"].append(unpack('<f', m_weights.read(8))[0])
for i in rna.code:
# Go to the desired entry in datafile
m_weights.seek(i * 4)
rna.metadata["baseWeights"].append(unpack('<f', m_weights.read(8))[0])
return rna
return rna
......@@ -14,27 +14,27 @@ filename = mypath + '/codonWeights.dat'
try:
m_file = open(filename,'+b') # update binary file
m_file = open(filename,'+b') # update binary file
except OSError as e:
print("\"" + filename + "\" not found!\n"
+ "Constructing new file...", file=sys.stderr)
m_file = open(filename,'x+b') # create and update bytecode file
# Pack 64 little endian floats, all set to 0.0, into a bytearray and
# write to the file
m_file.write(bytearray(pack('<' + 'f'*64, *([0.0]*64))))
sys.exit()
print("\"" + filename + "\" not found!\n"
+ "Constructing new file...", file=sys.stderr)
m_file = open(filename,'x+b') # create and update bytecode file
# Pack 64 little endian floats, all set to 0.0, into a bytearray and
# write to the file
m_file.write(bytearray(pack('<' + 'f'*64, *([0.0]*64))))
sys.exit()
parser = argparse.ArgumentParser(description="A helper utility for populating "
+ "the \"" + filename + "\" file"
, epilog="For an example of the file format, run the program without any "
+ "arguments (line order can be arbitrary, no upper or lower limit on "
+ "file size). New entries or later entries in the file override older ones"
, formatter_class=argparse.RawDescriptionHelpFormatter)
+ "arguments (line order can be arbitrary, no upper or lower limit on "
+ "file size). New entries or later entries in the file override older ones"
, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('infile', nargs='*', type=argparse.FileType('r')
, help="Read weights stored in a file and update \""+ filename + "\" with "
+ "the new data. Leave empty to print out currently stored data")
, help="Read weights stored in a file and update \""+ filename + "\" with "
+ "the new data. Leave empty to print out currently stored data")
args = parser.parse_args()
......@@ -42,18 +42,18 @@ args = parser.parse_args()
# If empty, print the current weights in the same format they are input
if args.infile == []:
for i in range(64):
print(mRNA.deindexCodon(i) + " ", *unpack('<f', m_file.read(8)))
sys.exit()
for i in range(64):
print(mRNA.deindexCodon(i) + " ", *unpack('<f', 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
# Index RNA and use this value to find desired entry in datafile
m_file.seek(mRNA.indexCodon(codon) * 4)
# Pack weight into a little-endian float and write
m_file.write(bytearray(pack('<f', float(n_file.readline()))))
while True:
codon = n_file.read(4)
if codon == None or codon == "":
break
# Index RNA and use this value to find desired entry in datafile
m_file.seek(mRNA.indexCodon(codon) * 4)
# Pack weight into a little-endian float and write
m_file.write(bytearray(pack('<f', float(n_file.readline()))))
......@@ -8,6 +8,6 @@
**Contents:**
-*protloc.py* Main end user program
-*locStrings.txt* Alphabetized list of known localization strings
-*protloc.py* Main end user program
-*locStrings.txt* Alphabetized list of known localization strings
......@@ -14,42 +14,42 @@ aminoCodons = "KNKNIIMIRSRSTTTT*Y*YLFLF*CWCSSSSEDEDVVVVGGGGAAAAQHQHLLLLRRRRPPPP"
# Take a coding sequence and return the Amino Acid Chain it will translate into
def convertRNA(seq:list, stcodon =0) -> list:
result:list = []
for i in range(0, len(seq), 3):
amino = aminoCodons[seq[i]]
if (amino == '*')
break
result.append(amino)
return result
result:list = []
for i in range(0, len(seq), 3):
amino = aminoCodons[seq[i]]
if (amino == '*')
break
result.append(amino)
return result
class AminoAcidChain:
# Instantiates a new AminoAcidChain object using plain text
def __init__(self, seq:string):
self.sequence:string = seq
self.length:int = len(seq)
self.metadata:list = []
# Takes
# an mRNA object, a string of RNA in plain text, or an RNA index list
# and
# the codon index to begin reading from
# and returns a new AminoAcidChain
@classmethod
def fromCodingSequence(cls, seq, stcodon =0):
if isinstance(seq, mRNA.mRNA):
seq = seq.code
if isinstance(seq, str):
seq = indexRNA(seq)
if isinstance(seq, list):
return cls(convertRNA(seq, stcodon))
else:
raise TypeError("'seq' must be of type 'mRNA', 'str', or 'list'")
def __str__(self) -> str:
return self.sequence + "\n\n" + self.metadata
# Instantiates a new AminoAcidChain object using plain text
def __init__(self, seq:string):
self.sequence:string = seq
self.length:int = len(seq)
self.metadata:list = []
# Takes
# an mRNA object, a string of RNA in plain text, or an RNA index list
# and
# the codon index to begin reading from
# and returns a new AminoAcidChain
@classmethod
def fromCodingSequence(cls, seq, stcodon =0):
if isinstance(seq, mRNA.mRNA):
seq = seq.code
if isinstance(seq, str):
seq = indexRNA(seq)
if isinstance(seq, list):
return cls(convertRNA(seq, stcodon))
else:
raise TypeError("'seq' must be of type 'mRNA', 'str', or 'list'")
def __str__(self) -> str:
return self.sequence + "\n\n" + self.metadata
......@@ -8,6 +8,6 @@
**Contents:**
-*mRNA.py* Utils for dealing with strands of mRNA
-*AminoChain.py* Utils for dealing with chains of Amino Acids
-*misc-util.py* What it says on the tin.
-*mRNA.py* Utils for dealing with strands of mRNA
-*AminoChain.py* Utils for dealing with chains of Amino Acids
-*misc-util.py* What it says on the tin.
......@@ -12,82 +12,91 @@ bases = ['A', 'U', 'G', 'C'];
def deindexCodon(index:int) -> str:
result = bases[int(index/16)]
result += bases[int((index/4))%4]
result += bases[index%4]
return result
result = bases[int(index/16)]
result += bases[int((index/4))%4]
result += bases[index%4]
return result
def deindexRNA(code:list) -> str:
result = ''
for i in range (0, len(code), 3):
result = result + codonIndex(code[i])
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
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
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
result = []
for i in range(len(code) - 2):
result.append(indexCodon(code[i:i+3]))
return result
class mRNA:
def __init__(self, cd):
if isinstance(cd, str):
cd = indexRNA(cd)
if not isinstance(cd, list):
raise TypeError("'cd' must be of type 'str' or 'list'")
def __init__(self, cd):
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.code:list = cd
self.baseWeights:list = []
<<<<<<< Updated upstream
self.baseWeights:list = []
self.modifiers:list = []
self.modifiers:list = []
self.adjustedWeights:list = []
self.adjustedWeights:list = []
=======
# DEPRECATED! USE METADATA DICT INSTEAD!!!!!
self.baseWeights:list = []
self.adjustedWeights:list = []
# ^^^^^^^^^^^^ DEPRECATED ^^^^^^^^^^^^^^^^^^
self.metadata:dictionary = {}
>>>>>>> Stashed changes
def __str__(self) -> str:
return rnaIndex(self.code) + "\n\n" + self.metadata
def __str__(self) -> str:
return rnaIndex(self.code) + "\n\n" + self.metadata
class Iterable(mRNA) :
def __init__(self, parent:mRNA, start:int, stop:int):
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
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 __iter__(self):
return self
def next(self):
self.loc += 3
if self.loc >= self.stop:
raise StopIteration
def next(self):
self.loc += 3
if self.loc >= self.stop:
raise StopIteration
value = self.parent.code[self.loc:(self.loc + 3)]
return value
value = self.parent.code[self.loc:(self.loc + 3)]
return value
# Find index in a sorted list. If not found, returns the negated index of the
# nearest value #TODO
def stubbornBinSearch(list, object) -> int:
i = list.len() / 2
j = 0
while (list[i] != object && i != j):
return ((i == j) * -1) * i;
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