Skip to content
Snippets Groups Projects
Commit 472dca50 authored by Alice Brenon's avatar Alice Brenon
Browse files

Add the ability to set the resolution from the command line in the profile visualisation script

parent a9d97de5
No related branches found
No related tags found
No related merge requests found
...@@ -12,9 +12,10 @@ def gate(measure): ...@@ -12,9 +12,10 @@ def gate(measure):
return [1 if i >= first and i < last else 0 return [1 if i >= first and i < last else 0
for i in range(1, 1 + measure['totalSize'])] for i in range(1, 1 + measure['totalSize'])]
def plotProfile(profile, outputPath): def plotDensity(profile, outputPath):
plot.figure(figsize=(16,13)) plot.figure(figsize=(16,13))
ax = seaborn.lineplot(profile) l = len(profile)
ax = seaborn.lineplot(x=[100*i/(l-1) for i in range(l)], y=profile)
ax.set_xlabel("Position") ax.set_xlabel("Position")
ax.set_xlim(0, 100) ax.set_xlim(0, 100)
ax.set_ylim(0) ax.set_ylim(0)
...@@ -29,7 +30,7 @@ def plotProfile(profile, outputPath): ...@@ -29,7 +30,7 @@ def plotProfile(profile, outputPath):
def sumProfiles(sameSizeProfiles): def sumProfiles(sameSizeProfiles):
return list(map(sum, zip(*sameSizeProfiles))) return list(map(sum, zip(*sameSizeProfiles)))
def computeProfile(measures, resolution=100): def computeProfile(measures, resolution):
bySize, count = {}, 0 bySize, count = {}, 0
for measure in measures: for measure in measures:
distribution = gate(measure) distribution = gate(measure)
...@@ -39,13 +40,28 @@ def computeProfile(measures, resolution=100): ...@@ -39,13 +40,28 @@ def computeProfile(measures, resolution=100):
bySize[l] = [] bySize[l] = []
bySize[l].append(distribution) bySize[l].append(distribution)
resampled = map(resample(resolution), map(sumProfiles, bySize.values())) resampled = map(resample(resolution), map(sumProfiles, bySize.values()))
return [100*x/count for x in sumProfiles(list(resampled))] return [resolution*x/count for x in sumProfiles(list(resampled))]
def visualiseProfile(measures, outputPath): def visualiseProfile(measures, outputPath, resolution=100):
profile = computeProfile(measures) profile = computeProfile(measures, resolution)
toTSV(prepare(f"{outputPath}/profile.tsv"), profile, sortBy=None) toTSV(prepare(f"{outputPath}/profile.tsv"), profile, sortBy=None)
plotProfile(profile, f"{outputPath}/profile.png") plotDensity(profile, f"{outputPath}/profile.png")
def parseArgs(args):
positional = []
kwargs = {}
i = 0
while i < len(args):
if args[i] == '--resolution':
kwargs['resolution'] = int(args[i+1])
i += 1
else:
positional.append(args[i])
i += 1
return positional, kwargs
if __name__ == '__main__': if __name__ == '__main__':
visualiseProfile([measure for _, measure in fromTSV(argv[1]).iterrows()], args, kwargs = parseArgs(argv[1:])
argv[2]) visualiseProfile([measure for _, measure in fromTSV(args[0]).iterrows()],
args[1],
**kwargs)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment