File: Nx_plot.py

package info (click to toggle)
spades 3.13.1+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 22,172 kB
  • sloc: cpp: 136,213; ansic: 48,218; python: 16,809; perl: 4,252; sh: 2,115; java: 890; makefile: 507; pascal: 348; xml: 303
file content (61 lines) | stat: -rw-r--r-- 1,652 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python3
############################################################################
# Copyright (c) 2015 Saint Petersburg State University
# Copyright (c) 2011-2014 Saint Petersburg Academic University
# All Rights Reserved
# See file LICENSE for details.
############################################################################


# N00-N50-N100 plotter
# mailto: vyahhi@gmail.com

import sys
import pylab
import matplotlib.ticker
import fastaparser

# check command line arguments
if len(sys.argv) < 2:
	print "Draws Nx plot (from N00 through N50 to N100)"
	print
	print "Usage: python3", sys.argv[0], "FASTA1 [FASTA2 [FASTA3 ..."
	print
	print "Example: python3", sys.argv[0], "../../data/debruijn/we_contigs.fasta ../../data/debruijn/velvet_contigs.fa"
	exit(0)

for filename in sys.argv[1:]:
	# parse
	lengths = fastaparser.get_lengths_from_fastafile(filename)
	lengths.sort()
	# calculate values for the plot
	vals_Nx = [0.0]
	vals_l = [0]
	lcur = 0
	lsum = sum(lengths)
	for l in lengths:
		lcur += l
		x = lcur * 100.0 / lsum
		vals_Nx.append(vals_Nx[-1] + 1e-10) # eps
		vals_l.append(l)
		vals_Nx.append(x)
		vals_l.append(l)
	# add to plot
	pylab.plot(vals_Nx, vals_l)

# customize plot
pylab.xlabel('Nx')
pylab.ylabel('Contig length')
pylab.title('Nx plot (N00 to N100)')
pylab.grid(True)
ax = pylab.gca()
#ax.legend(["Our Assembler", "Velvet"], loc='lower right')
ax.legend(sys.argv[1:], loc='lower right')
formatter = matplotlib.ticker.FormatStrFormatter('N%.f')
ax.xaxis.set_major_formatter(formatter)

# save and show
filename = 'Nx_plot.pdf'
pylab.savefig(filename)
print "Saved to ./" + filename #+ ".png"
pylab.show()