Coder Social home page Coder Social logo

genetracks's Introduction

genetracks

Generate track diagrams for genomic alignments

see examples/Genetracks.ipynb for use cases

Example

from genetracks import Figure, Track
import pysam
import sys

f = Figure()

for alignment in pysam.AlignmentFile(sys.argv[1]):
  f.add(Track(alignment.query_start, alignment.query_end))

f.show(w=900).save_svg("alignment.svg")

JSON serialisation

...

genetracks's People

Contributors

cbeelen avatar donkirkby avatar jeff-k avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

cfe-lab

genetracks's Issues

Simplify coverage plots

I created a subclass of Coverage in the MiCall project. It simplifies the coverage plots by joining all the rectangles that are within 10% of the starting coverage value. That reduces most SVG file sizes to less than 10% of their current size.

Let me know if you like the technique, and I'll create a pull request for you to put this feature in Coverage. The next class in that file is ShadedCoverage to set colour based on coverage depth. You're welcome to that as well, but it might not be as generally useful. It also introduces a matplotlib dependency, although I could probably work around that if needed.

I hope your adventure is not too adventurous. Talk to you later.

Vertical padding ignores track height

How are things, Jeff? I ran into a quirk in the interface for this library.

If you increase the height of a track, the default vertical position doesn't adjust.

Here's an example:

from genetracks import Figure, Track

f = Figure()
f.add(Track(100, 200, label='Foo'))
f.add(Track(10, 90, h=50, label='Bar'))
drawing = f.show()
with open('test.png', 'wb') as f:
    drawing.rasterize(f)

That produces this diagram, where the Bar track is colliding with the Foo track.

test

I can work around it with the padding parameter, but I'd rather fix the default position. I'll create a pull request for you.

from genetracks import Figure, Track

f = Figure()
f.add(Track(100, 200, label='Foo'))
f.add(Track(10, 90, h=50, label='Bar'), padding=50)
drawing = f.show()
with open('test.png', 'wb') as f:
    drawing.rasterize(f)

That makes it look like this:

test

Adjust text anchor of labels

We've run into problems with short tracks near the left or right edges. If the label is longer than the track rectangle, then the label text can flow past the edge of the diagram.

Here's an example, including our current workaround:

from genetracks import Figure, Track, Multitrack

f = Figure()

f.add(Track(1, 1500, label='Track with a long contig'))

# The problem
f.add(Track(1, 150, label='Track with a long name'))

# A workaround
f.add(Multitrack([Track(1, 150),
                  Track(1,
                        1500,
                        label='Short track with centred name',
                        color='none')]))

f.show(w=900).saveSvg("alignment.svg")

Here's how it looks:

alignment

I thought it might be helpful to set the text-anchor attribute of the labels. I don't think there's a good way to estimate the width of the text, so the best I could think of was to use start when the track starts on the left third of the diagram, middle when it starts in the middle third, and end when it starts on the right third.

If you think that's a reasonable approach, I can prepare a pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.