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

Can this tools generate a PDF or svg file? #2

Closed
Orz-CQ opened this issue Jun 2, 2022 · 1 comment
Closed

Can this tools generate a PDF or svg file? #2

Orz-CQ opened this issue Jun 2, 2022 · 1 comment
Labels
question Further information is requested

Comments

@Orz-CQ
Copy link

Orz-CQ commented Jun 2, 2022

Hi,
It is such an amazing tools! I love this pattern to show the msa results.
But I am wondering if it can generante a PDF file that contain the output show in the terminal?

Lan

@althonos
Copy link
Owner

althonos commented Jun 2, 2022

Hi Lan!

The RichAlignment is a rich renderable object, and rich implements exporting to SVG. You can get a result Simply print to a console in record mode and use the Console.export_svg method to get an SVG representation.

For instance:

import Bio.AlignIO
import rich
from rich_msa import RichAlignment

msa = Bio.AlignIO.read("tests/data/swissprot-halorhodopsin.muscle.afa", "fasta")
viewer = RichAlignment(
    names=[record.id for record in msa],
    sequences=[str(record.seq) for record in msa],
)

console = rich.console.Console(record=True, quiet=True)
console.print(viewer)

with open("example.svg", "w") as f:
    f.write(console.export_svg())

This will write a SVG file named example.svg the following content:
example

@althonos althonos closed this as completed Jun 2, 2022
@althonos althonos added the question Further information is requested label Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants