Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix annotation bug and make some beautifications #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,4 @@ manhattan_generator \
```

<img src=https://raw.github.com/pgxcentre/manhattan_generator/master/example_giant.png width=728 />
<img src=https://raw.github.com/Jiashun-Xiao/manhattan_generator/master/example_annotation.png width=728 />
Binary file added example_annotation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 18 additions & 9 deletions manhattan_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,28 +414,32 @@ def create_manhattan_plot(twopoint, multipoint, args):
mec=args.significant_color)

# If we want annotation
count=0
if not args.no_annotation:
for m_index, m in chrom_twopoint[sig_mask].iterrows():
chr_sig_snp = chrom_twopoint[sig_mask]
chr_sig_snp = chr_sig_snp.sort_values(['conf'],ascending=False)
for m_index, m in chr_sig_snp.iterrows():
# The confidence to write
the_conf = "{:.3f}".format(m.conf)
if args.use_pvalues_flag:
the_conf = str(10 ** (-1 * m.conf))

# The label of the annotation
label = "\n".join([m.snp, the_conf])
label = m.snp#"\n".join([m.snp, the_conf])

annot = ax.annotate(
label,
xy=(m.pos + starting_pos, m.conf),
xycoords="data",
size=10,
xytext=(m.pos + starting_pos, conf_max),
size=7,
xytext=(m.pos + starting_pos+50000000, conf_max-count*0.33),
va="center",
bbox=dict(boxstyle="round", fc="white", ec="black"),
bbox=dict(boxstyle="round", fc="white", alpha=0.4),
textcoords="data",
arrowprops=dict(arrowstyle="->", shrinkA=6, shrinkB=5),
arrowprops=dict(arrowstyle="->",connectionstyle=mpl.patches.ConnectionStyle("Arc3, rad=0.15"),color='grey',alpha=0.6),
)
annots.append(annot)
count +=1

# Changing the starting point for the next chromosome
starting_pos = max_pos + starting_pos + chrom_spacing
Expand Down Expand Up @@ -482,7 +486,12 @@ def create_manhattan_plot(twopoint, multipoint, args):
else:
# There is some two-point data and annotation is asked, se we show
# the figure
plt.show()
plt.savefig(args.outFile_name + "." + args.graph_format,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else is now irrelevant, since the same code is executed in both cases.

bbox_inches="tight")
if args.graph_format != "png":
plt.savefig(args.outFile_name + ".png", bbox_inches="tight")
if args.web:
print(args.outFile_name + ".png")


def encode_chr(chromosome):
Expand Down Expand Up @@ -636,7 +645,7 @@ def parse_args():
comma
``--significant-threshold`` Float The significant threshold for
linkage
``--no-annotation`` Boolean Do not draw annotation (SNP names)
``--no_annotation`` Boolean Do not draw annotation (SNP names)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please stay with previous options, so that it doesn't change existing scripts (--no-annotation).

for the significant results
``--chromosome-box-color`` String The *color* for the box surrounding
even chromosome numbers
Expand Down Expand Up @@ -893,7 +902,7 @@ def parse_args():

# The annotation flag
group.add_argument(
"--no-annotation", action="store_true",
"--no_annotation", action="store_true",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, keep --no-annotation).

help="Do not draw annotation (SNP names) for the significant results.",
)

Expand Down