Commit 8dbbeca4 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Cleanup code

parent ec72c85d
......@@ -10,62 +10,62 @@ parser.add_argument('--output', '-o', required=True, help='The converted results
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' or elements[i] == 'o':
location = ""
if elements[i] == 'i':
location = "inside"
else:
location = "outside"
if i == 0:
if len(elements) == 1:
result.append({'start': 1, 'end': l , 'location': location})
else:
result.append({'start': 1, 'end': elements[i+1]-1 , 'location': location})
elif i+1 == len(elements):
result.append({'start': elements[i-1]+1, 'end':l , 'location': location})
else:
result.append({'start': elements[i-1]+1, 'end': elements[i+1]-1 , 'location': location})
else:
result.append({'start': elements[i], 'end': elements[i+1] , 'location': 'membrane'})
flag = True
return (result)
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' or elements[i] == 'o':
location = ""
if elements[i] == 'i':
location = "inside"
else:
location = "outside"
if i == 0:
if len(elements) == 1:
result.append({'start': 1, 'end': l , 'location': location})
else:
result.append({'start': 1, 'end': elements[i+1]-1 , 'location': location})
elif i+1 == len(elements):
result.append({'start': elements[i-1]+1, 'end':l , 'location': location})
else:
result.append({'start': elements[i-1]+1, 'end': elements[i+1]-1 , 'location': location})
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:
for line in f:
line_dic = {}
elements = line.rstrip().split("\t")
for i in range(1, len(elements)):
key = elements[i][:elements[i].rfind('=')]
value = elements[i][elements[i].rfind('=')+1:]
if key == 'Topology':
line_dic['topology'] = parse_topology(value, int(elements[i-4][elements[i-4].rfind('=')+1:]))
elif key == 'PredHel':
line_dic[key] = int(value)
elif not key == 'len':
line_dic[key] = float(value)
documents[elements[0]] = {'computations': [{'tool': {'name': 'TMHMM', 'version': '2.0'}, 'results': line_dic}]}
for line in f:
line_dic = {}
elements = line.rstrip().split("\t")
for i in range(1, len(elements)):
key = elements[i][:elements[i].rfind('=')]
value = elements[i][elements[i].rfind('=')+1:]
if key == 'Topology':
line_dic['topology'] = parse_topology(value, int(elements[i-4][elements[i-4].rfind('=')+1:]))
elif key == 'PredHel':
line_dic[key] = int(value)
elif not key == 'len':
line_dic[key] = float(value)
documents[elements[0]] = {'computations': [{'tool': {'name': 'TMHMM', 'version': '2.0'}, 'results': line_dic}]}
output_filename = args.output
with open(output_filename, 'w') as o:
json.dump(documents, o)
json.dump(documents, o)
......@@ -9,18 +9,6 @@ tmhmm_tool = config.load_config()['tools'].get('tmhmm', 'tmhmm')
parser = argparse.ArgumentParser(description='Find transmembrane helices in amino acid sequences')
parser.add_argument('--fasta', '-f', required=True, help='A fasta file with aminoacid sequences')
#parser.add_argument('--workdir', '-workdir', help='Working directory')
#parser.add_argument('--wwwdir', '-wwwdir', help='The place where the www server looks for files')
#parser.add_argument('--serverhome', '-serverhome', help='') #
#parser.add_argument('--basedir', '-basedir', help='basis directory for TMHMM package')
#parser.add_argument('--bindir', '-bindir', help='Bin directory (defaults basedir/bin)')
#parser.add_argument('--scrdir', '-scrdir', help='Script directory (defaults basedir/bin)')
#parser.add_argument('--libdir', '-libdir', help='Library directory (defaults basedir/lib)')
#parser.add_argument('--html', '-html', help='Produce HTML output')
#parser.add_argument('--short', '-s', help='Short output format')
#parser.add_argument('--plot', '-p', help='Produce graphics')
#parser.add_argument('--version1', '-v1', help='Use old model (version 1)')
#parser.add_argument('--debugging', '-d', help='') #
parser.add_argument('--output', required=True, help='The output file')
args = parser.parse_args()
......
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