Commit 59e8fb34 authored by Pauline Pommeret's avatar Pauline Pommeret
Browse files

[file_tools] Optimization of md reader function.

parent 56ae4986
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
Docstring Docstring
""" """
import re
from Bio import SeqIO from Bio import SeqIO
from Bio.Alphabet import IUPAC from Bio.Alphabet import IUPAC
...@@ -45,7 +46,9 @@ def load_md_data(path): ...@@ -45,7 +46,9 @@ def load_md_data(path):
positions.append(re.sub(r'[A-Z]', '', header[-1].split('/')[1])) positions.append(re.sub(r'[A-Z]', '', header[-1].split('/')[1]))
# Getting rid of 'frame' (first word of the file) # Getting rid of 'frame' (first word of the file)
positions.pop(0) # And getting rid of the last position.
_ = positions.pop(0)
_ = positions.pop(-1)
# Starting to work on the 'real' data (frame 0) # Starting to work on the 'real' data (frame 0)
line = handle.readline() line = handle.readline()
...@@ -58,19 +61,19 @@ def load_md_data(path): ...@@ -58,19 +61,19 @@ def load_md_data(path):
# Casting the frame number to int and the helicoidal parameter # Casting the frame number to int and the helicoidal parameter
# values to float for further use # values to float for further use
newline = [int(line[0]]) + [float(x) for x in line[1:]] line = [int(line[0])] + [float(x) for x in line[1:]]
# Creating a list looking like # Creating a list looking like
# [..., ['position_i', 'helicoidal_parameter_value_i'], ...] # [..., ['position_i', 'helicoidal_parameter_value_i'], ...]
# There is a shift between positions (contains frame number) and # There is a shift between positions (contains frame number) and
# line (doesn't) # line (doesn't)
newline = [[int(positions[x]), line[x+1]] for x in xrange(len(positions))] newline = { int(positions[x]): line[x+1] for x in xrange(len(positions))}
# Inserting the list ["frame", frame number] at first position # Inserting the list ["frame", frame number] at first position
# (for developper convenience) # (for developper convenience)
newline.insert(0, ["frame", line[0]]) newline["frame"] = line[0]
# Saving the processed line to the output # Saving the processed line to the output
output.append(newline) output.append(newline)
# Next line # Next line
line = handle.readline() line = handle.readline()
return (positions, output) return output
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