Skip to content

Commit

Permalink
Merge pull request #93 from Clinical-Genomics-Lund/allow-for-chrom-wo…
Browse files Browse the repository at this point in the history
…-cov

Allow for chrom wo cov
  • Loading branch information
mhkc authored Nov 17, 2021
2 parents 15d8eb8 + 667fc55 commit 0083ee9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ About changelog [here](https://keepachangelog.com/en/1.0.0/)
- Display viewed chromosome region in cytogenetic ideogram figure
### Changed
### Fixed
- Can now display samples that doesnt have data on all chromosomes

## [2.0.1]
### Added
Expand Down
63 changes: 45 additions & 18 deletions assets/js/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ export class OverviewCanvas extends BaseScatterTrack {
this.topBottomPadding = 8 // Padding for top and bottom in graph
this.leftmostPoint = this.x + 10 // Draw y-values for graph left of this point

// Setup canvas for repeated patterns
this.patternCanvas = document.createElement('canvas')
const size = 20
this.patternCanvas.width = size
this.patternCanvas.height = size
const patternCtx = this.patternCanvas.getContext('2d')
patternCtx.fillStyle = "#E6E9ED"
patternCtx.strokeStyle = "#4C6D94"
patternCtx.lineWidth = Math.round(size / 10)
patternCtx.lineCap = 'square'
patternCtx.fillRect(0, 0, size, size)
patternCtx.moveTo(size / 2, 0)
patternCtx.lineTo(size, size / 2)
patternCtx.moveTo(0, size / 2)
patternCtx.lineTo(size / 2, size)
patternCtx.stroke()

// BAF values
this.baf = {
yStart: 1.0, // Start value for y axis
Expand All @@ -39,6 +56,7 @@ export class OverviewCanvas extends BaseScatterTrack {
}

// Canvas variables
this.disabledChroms = []
this.width = document.body.clientWidth // Canvas width
this.height = this.y + 2 * this.plotHeight + 2 * this.topBottomPadding // Canvas height
this.drawCanvas.width = parseInt(this.width)
Expand All @@ -58,14 +76,16 @@ export class OverviewCanvas extends BaseScatterTrack {
this.staticCanvas.addEventListener('mousedown', event => {
event.stopPropagation()
const selectedChrom = this.pixelPosToGenomicLoc(event.x)
// Dont update if chrom previously selected
// Move interactive view to selected region
const chrom = selectedChrom.chrom
const start = 1
const end = this.dims[chrom].size - 1
// Mark region
this.markRegion({ chrom, start, end })
drawTrack({ chrom, start, end }) // redraw canvas
if (!this.disabledChroms.includes(selectedChrom.chrom)) {
// Dont update if chrom previously selected
// Move interactive view to selected region
const chrom = selectedChrom.chrom
const start = 1
const end = this.dims[chrom].size - 1
// Mark region
this.markRegion({ chrom, start, end })
drawTrack({ chrom, start, end }) // redraw canvas
}
})
this.staticCanvas.parentElement.addEventListener('mark-region', event => {
this.markRegion({ ...event.detail.region })
Expand Down Expand Up @@ -182,16 +202,23 @@ export class OverviewCanvas extends BaseScatterTrack {
height: this.plotHeight
})
// Plot scatter data
drawPoints({
ctx,
data: chromCovData.baf,
color: this.baf.color
})
drawPoints({
ctx,
data: chromCovData.data,
color: this.log2.color
})
if ( chromCovData.baf.length > 0 || chromCovData.data.length > 0 ) {
drawPoints({
ctx,
data: chromCovData.baf,
color: this.baf.color
})
drawPoints({
ctx,
data: chromCovData.data,
color: this.log2.color
})
} else {
const pattern = ctx.createPattern(this.patternCanvas, 'repeat')
ctx.fillStyle = pattern
ctx.fillRect(chromCovData.x_pos, chromCovData.y_pos + 1, width - 2, (this.plotHeight * 2) - 2)
this.disabledChroms.push(chrom)
}
}

async drawOverviewContent (printing) {
Expand Down
3 changes: 2 additions & 1 deletion assets/js/track/variant.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ export class VariantTrack extends BaseAnnotationTrack {
{ title: 'Ref', value: `${variant.reference}` },
{ title: 'Alt', value: `${variant.alternative}` },
{ title: 'Cytoband start/end', value: `${variant.cytoband_start}/${variant.cytoband_end}` },
{ title: 'Quality', value: `${variant.quality}` }
{ title: 'Quality', value: `${variant.quality}` },
{ title: 'Rank score', value: `${variant.rank_score}` }
]
})
this.trackContainer.appendChild(tooltip)
Expand Down
2 changes: 1 addition & 1 deletion gens/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,5 @@ def get_cov(req, x_ampl, json_data=None, cov_fh=None, baf_fh=None):
data_type=data_type,
)
if not new_start_pos and not log2_records and not baf_records:
raise NoRecordsException("No records")
LOG.warning("No records for region")
return region, new_start_pos, new_end_pos, log2_records, baf_records

0 comments on commit 0083ee9

Please sign in to comment.