Commit da70211c authored by Pauline Pommeret's avatar Pauline Pommeret
Browse files

[trx_tools] translate_trx_scale and parse function

parent 905dd8ac
#!/usr/bin/env python2.7
# This dictionary is there to translate TRX scale
nucleotide_map = { "Y" : "[CT]", "R" : "[AG]"}
def translate_trx_scale(pattern, nucleotide_map):
Translates a matching pattern so that it can be used with regexps.
It uses a nucleotide map.
Example: "YCGR" becomes "[CT]CG[AG]"
# NB: D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
return "".join([nucleotide_map.get(i,i) for i in pattern])
def parse_trx_scale(path_to_scale):
Parses a TRX scale file and creates a dictionary with the scale. It uses
translate_trx_scale in order to use unambiguous DNA alphabet later.
TRX = {}
with open(path_to_scale, "r") as handle:
line = handle.readline()
# Processing every data line
while line:
# Not taking into account empty lines and lines starting with
# # (comments)
if line.strip() != "" and (line.startswith("#") == False):
print line.split()[0] + " " + translate_trx_scale(line.split()[0], nucleotide_map)
TRX[translate_trx_scale(line.split()[0], nucleotide_map)] = float(line.split()[1])
line = handle.readline()
# At this point, we have a TRX dictionary that looks like this:
# TRX = {'AA' : 5.0, ..., 'YCGR': 59.0, ...}
# we need to translate Y and R
Supports Markdown
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