gosling-lang/gos

Examples of pile displacement

sapoudel opened this issue · 2 comments

Hi,
I am having trouble getting points to pile up. I tried something like this:

transform = gos.DisplaceTransform(boundingBox={"startField": "start:G", "endField": "end:G"},
                                  method=gos.DisplacementType("pile"),
                                  type="displace", newField="start", maxRows=20)
pile = gos.Displacement(gos.DisplacementType('pile'), padding=3.5)

seq_track = gos.Track(data, displacement=pile, dataTransform=[transform]).properties(height=150)
snp_mark = seq_track.mark_point(
).encode(
    x=gos.X("start:G", axis="bottom", linkingId='detail-1'),
    color=gos.Color("qval:Q", legend=True),
).properties(
    layout="linear", width=900, height=80,
    assembly=current_assembly)

The above code passes validation but doesn't render anything if I pass displacement or dataTransform to Track. I have tried using with dataTransform parameter only, but no luck. One thing that I am unsure of is what the value of newField parameter in gosling.DataTransform class is supposed to.

In case you need the full code, here it is:

Hi @sapoudel, thanks for leaving a question, and apologize for the delayed response!

One thing that I am unsure of is what the value of newField parameter in gosling.DataTransform class is supposed to.

The newField is a field name that will be generated by the data transform. It stores the row numbers (e.g., 1, 2, 3, etc) after computing the pilling algorithm.

So, with the current code, these row numbers will be overwritten to the start field.

I can find three parts that you can change to fix the issue:

  1. Set newField other than "start" (e.g., newField="pileup")
  2. Use the field to encode row (i.e., add row=gos.Row("pileup:N"))
  3. Remove displacement=pile. This is not needed since you already use pile dataTransform.

This is an working example that you can refer to:

data = gos.bam(
    url="https://s3.amazonaws.com/gosling-lang.org/data/example_higlass.bam",
    indexUrl="https://s3.amazonaws.com/gosling-lang.org/data/example_higlass.bam.bai",
)

base = gos.Track(data).transform_displace(
    method="pile",
    newField="pileup",
    boundingBox=dict(
        startField="start",
        endField="end",
        padding=5,
    ),
).transform_json_parse(
    field="substitutions",
    genomicField="pos",
    baseGenomicField="start", //Change 1
    genomicLengthField="length",
).properties(
    height=500,
)

reads = base.mark_rect().encode(
    x=gos.X("start:G"),
    xe=gos.Xe("end:G"),
    row=gos.Row("pileup:N", padding=0.2),
    color=gos.value("#C8C8C8")
)

variants = reads.encode(
    x=gos.X("pos_start:G"),
    xe=gos.Xe("pos_end:G"),
    color=gos.Color("variant:N"),
)

gos.overlay(reads, variants).properties(
    xDomain=gos.GenomicDomain(chromosome="chr1", interval=[136750, 139450])
)

image

If you can share the full code, I can more accurately help you.

Thank you! I can fix my code using this example!