Skip to content

Commit

Permalink
cnvpytor bug fix -- undefined bin_size and genome_size
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Aug 30, 2023
1 parent 78722b8 commit 234e575
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 6 deletions.
41 changes: 41 additions & 0 deletions dev/cnvpytor/cnvpytorTrackVCF.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link href=https://igv.org/web/img/favicon.ico rel="shortcut icon">
<title>igv</title>

</head>

<body>

<h2>CNVpytor Track</h2>


<div id="igvDiv" style="padding-top: 50px;padding-bottom: 20px; height: auto"></div>

<script type="module">

import igv from "../../dist/igv.esm.js"
const options =
{
genome: "hg19",
locus: "chr16",
tracks: [
{
type: "cnvpytor",
name: "HepG2 VCF",
url: "https://www.dropbox.com/scl/fi/gbnfsvkf44oe6ibod87t2/HepG2.sample.vcf.gz?rlkey=bu787lu1aq0j4fvryal213e69&dl=0",
indexed: false

}
]
}

igv.createBrowser(document.getElementById('igvDiv'), options)


</script>

</body>

</html>
56 changes: 56 additions & 0 deletions dev/cnvpytor/cnvpytorTrackVCF_large.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link href=https://igv.org/web/img/favicon.ico rel="shortcut icon">
<title>igv</title>

</head>

<body>

<h2>CNVpytor Track</h2>

<button id="log-state">Log Session Json</button>
<button id="pytor">Change to Pytor</button>

<div id="igvDiv" style="padding-top: 50px;padding-bottom: 20px; height: auto"></div>

<script type="module">

import igv from "../../js/index.js"

const options =
{
genome: "hg19",
locus: "chr16",
tracks: [
// {
// type: "cnvpytor",
// name: "HepG2 VCF",
// url: "https://igv-genepattern-org.s3.amazonaws.com/test/pytor/HepG2.sample.vcf.gz"
//
// },
{
type: "variant",
name: "HepG2 VCF",
//url: "https://storage.googleapis.com/cnvpytor_data/HepG2.vcf.gz",
url: "https://igv-genepattern-org.s3.amazonaws.com/test/pytor/HepG2.sample.vcf.gz"
}
]
}

igv.createBrowser(document.getElementById('igvDiv'), options)
.then(browser => {
const track = browser.findTracks("type", "variant")[0];
document.getElementById("log-state").addEventListener("click", () => console.log(browser.toJSON()))
document.getElementById("pytor").addEventListener("click", () => {
track.convertToPytor()
})
})


</script>

</body>

</html>
40 changes: 40 additions & 0 deletions examples/cnvpytor/cnvpytorTrackVCF_small.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link href=https://igv.org/web/img/favicon.ico rel="shortcut icon">
<title>igv</title>

</head>

<body>

<h2>CNVpytor Track</h2>


<div id="igvDiv" style="padding-top: 50px;padding-bottom: 20px; height: auto"></div>

<script type="module">

import igv from "../../dist/igv.esm.js"
const options =
{
genome: "hg19",
locus: "chr16",
tracks: [
{
type: "cnvpytor",
name: "HepG2 VCF",
url: "https://storage.googleapis.com/cnvpytor_data/HepG2.vcf.gz",

}
]
}

igv.createBrowser(document.getElementById('igvDiv'), options)


</script>

</body>

</html>
12 changes: 7 additions & 5 deletions js/cnvpytor/MeanShiftUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import g_utils from './GeneralUtil.js'
import t_dist from './t_dist.js'

// TODO -- remove this hardcoded value
const genome_size = 2871000000;

function erf(x) {
var m = 1.0, s = 1.0, sum = x * 1.0;
Expand Down Expand Up @@ -122,7 +124,8 @@ export class Partition {
return new_array
}

meanShiftCaller(repeats = 3) {
meanShiftCaller(bins_size, repeats = 3) {

var ChrLevels = {}

Object.entries(this.rd).forEach(([chr, chr_rd]) => {
Expand Down Expand Up @@ -274,7 +277,6 @@ export class Partition {
call_mean_shift(repeats = 3) {
const bin_size = 1000;
// const genome_size = bin_size * this.rd.length;
const genome_size = 2871000000;
var masked = new Array(this.rd.length).fill(false);

// set the level
Expand Down Expand Up @@ -468,16 +470,16 @@ export class Partition {
}

cnv_calling(bin_size = 100000) {
var delta = 0.25
var delta = delta * this.mean

var delta = 0.25 * this.mean

var min = this.mean - delta, max = this.mean + delta;
// console.log('min: ', min, ', Max: ', max)

// console.log('delta', delta)
var normal_genome_size = 2971000000

var levels = this.meanShiftCaller()
var levels = this.meanShiftCaller(bin_size)


var merged_level = {}
Expand Down
2 changes: 1 addition & 1 deletion js/cnvpytor/cnvpytorVCF.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class CNVpytorVCF {

// Apply partition method
var partition = new read_depth_caller.Partition(wigFeatures, globamMean, globalStd);
var partition_array = partition.meanShiftCaller()
var partition_array = partition.meanShiftCaller(this.binSize)
var caller_array = partition.cnv_calling()

// Assign the partition values to each bin
Expand Down

0 comments on commit 234e575

Please sign in to comment.