Commit f08f7db6 authored by lmueller's avatar lmueller
Browse files

added method to resolve topology-string from tmhmm output

parent 202ab9c1
......@@ -8,6 +8,45 @@ parser.add_argument('--result', '-r', required=True, help='The tmhmm result file
parser.add_argument('--output', '-o', required=True, help='The converted results json file')
args = parser.parse_args()
def parse_topology(s, l):
elements = []
result = []
flag = False
num = ""
for c in s:
if c == 'i' or c == 'o' or c == '-':
if num != "":
elements.append(int(num))
num = ""
if c != '-':
elements.append(c)
else:
num += c
if num != "":
elements.append(int(num))
for i in range(len(elements)):
if flag:
flag = False
else:
if elements[i] == 'i':
if i == 0:
result.append({'start': 1, 'end':elements[i+1]-1 , 'location': 'inside'})
elif i+1 == len(elements):
result.append({'start': elements[i-1]+1, 'end':l , 'location': 'inside'})
else:
result.append({'start': elements[i-1]+1, 'end':elements[i+1]-1 , 'location': 'inside'})
elif elements[i] == 'o':
if i == 0:
result.append({'start': 1, 'end':elements[i+1]-1 , 'location': 'outside'})
elif i+1 == len(elements):
result.append({'start': elements[i-1]+1, 'end':l , 'location': 'outside'})
else:
result.append({'start': elements[i-1]+1, 'end':elements[i+1]-1 , 'location': 'outside'})
else:
result.append({'start': elements[i], 'end':elements[i+1] , 'location': 'membrane'})
flag = True
return (result)
filename = args.result
documents = {}
with open(filename) as f:
......@@ -15,7 +54,12 @@ with open(filename) as f:
line_dic = {}
elements = line.rstrip().split("\t")
for i in range(1, len(elements)):
line_dic[elements[i][:elements[i].rfind('=')]] = elements[i][elements[i].rfind('=')+1:]
key = elements[i][:elements[i].rfind('=')]
value = elements[i][elements[i].rfind('=')+1:]
if key == 'Topology':
line_dic[key] = parse_topology(value, elements[i-4][elements[i-4].rfind('=')+1:])
else:
line_dic[key] = value
documents[elements[0]] = line_dic
output_filename = args.output
......
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