Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Apr 30, 2024
1 parent b970e9a commit c865d6b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions jcvi/graphics/landscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
}


class BinLine(object):
class BinLine:
def __init__(self, row):
args = row.split()
self.chr = args[0]
Expand All @@ -70,7 +70,7 @@ def __init__(self, filename):
super(BinFile, self).__init__(filename)
self.mapping = defaultdict(list)

fp = open(filename)
fp = open(filename, encoding="utf-8")
for row in fp:
b = BinLine(row)
self.append(b)
Expand Down Expand Up @@ -125,13 +125,12 @@ def __init__(self, filename, delimiter=","):
def main():

actions = (
("stack", "create landscape plot with genic/te composition"),
("heatmap", "similar to stack but adding heatmap"),
("composite", "combine line plots, feature bars and alt-bars"),
("multilineplot", "combine multiple line plots in one vertical stack"),
# Related to chromosomal depth
("depth", "show per chromosome depth plot across genome"),
("heatmap", "similar to stack but adding heatmap"),
("mosdepth", "plot depth vs. coverage per chromosome"),
("multilineplot", "combine multiple line plots in one vertical stack"),
("stack", "create landscape plot with genic/te composition"),
)
p = ActionDispatcher(actions)
p.dispatch(globals())
Expand All @@ -152,7 +151,7 @@ def parse_distfile(filename):
dists = defaultdict(Counter)
with must_open(filename) as fp:
for row in fp:
chromosome, start, end, depth = row.split()
chromosome, _, _, depth = row.split()
depth = int(float(depth))
dists[chromosome][depth] += 1
logger.debug("Loaded %d seqids", len(dists))
Expand All @@ -171,7 +170,7 @@ def parse_groupsfile(filename):
filename (str): Path to the groups file.
"""
groups = []
with open(filename) as fp:
with open(filename, encoding="utf-8") as fp:
for row in fp:
chrs, colors = row.split()
groups.append((chrs.split(","), colors.split(",")))
Expand Down Expand Up @@ -579,7 +578,7 @@ def get_beds(s, binned=False):

def linearray(binfile, chr, window, shift):
mn = binfile.mapping[chr]
m, n = zip(*mn)
m, _ = zip(*mn)

m = np.array(m, dtype="float")
w = window // shift
Expand Down Expand Up @@ -718,7 +717,7 @@ def composite(args):
for bb in altbarbeds:
root.text(xend + 0.01, yy, bb.split(".")[0], va="center")
bb = Bed(bb)
for i, b in enumerate(bb):
for b in bb:
start, end = xs(b.start), xs(b.end)
span = end - start
if span < 0.0001:
Expand Down Expand Up @@ -1074,6 +1073,10 @@ def stack(args):
switch = DictFile(opts.switch)

stacks = opts.stacks.split(",")

fig = plt.figure(1, (iopts.w, iopts.h))
root = fig.add_axes((0, 0, 1, 1))

bedfiles = get_beds(stacks)
binfiles = get_binfiles(bedfiles, fastafile, shift, subtract=subtract, merge=merge)

Expand All @@ -1084,8 +1087,6 @@ def stack(args):
inner = 0.02 # y distance between tracks

pf = fastafile.rsplit(".", 1)[0]
fig = plt.figure(1, (iopts.w, iopts.h))
root = fig.add_axes((0, 0, 1, 1))

# Gauge
ratio = draw_gauge(root, margin, maxl)
Expand All @@ -1103,7 +1104,7 @@ def stack(args):
cc = ca[0].upper() + cb

if switch and cc in switch:
cc = "\n".join((cc, "({0})".format(switch[cc])))
cc = "\n".join((cc, f"({switch[cc]})"))

root.add_patch(Rectangle((xx, yy), xlen, yinterval - inner, color=gray))
ax = fig.add_axes((xx, yy, xlen, yinterval - inner))
Expand Down
2 changes: 1 addition & 1 deletion jcvi/projects/jcvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def diversity(args):

def landscape(args):
"""
%prog landscape features.bed athaliana.sizes Fig5.png
%prog landscape features.bed athaliana.sizes TAIR10_chr_all.fas Chr2
Plot landscape composite figure, including:
A. Example genomic features painted on Arabidopsis genome
Expand Down

0 comments on commit c865d6b

Please sign in to comment.