Skip to content

Commit

Permalink
update scale and bug fix for default cnv caller
Browse files Browse the repository at this point in the history
  • Loading branch information
arpanda committed Oct 12, 2023
1 parent b055f06 commit 8cdc14c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
6 changes: 3 additions & 3 deletions js/cnvpytor/CombinedCaller.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class CombinedCaller{
return results
}

formatDataStructure_BAF(feature_column, scaling_factor = 2) {
formatDataStructure_BAF(feature_column, scaling_factor = -1) {
const baf1 = []
const baf2 = []
for (const [chr, wig] of Object.entries(this.wigFeatures)) {
Expand All @@ -364,10 +364,10 @@ class CombinedCaller{

let value = sample[feature_column]
if (value != 0.5){
baf2_value.value = -2 * (1 - value)
baf2_value.value = scaling_factor * (1 - value)
baf2.push(baf2_value)
}
baf1_value.value = -2 * value
baf1_value.value = scaling_factor * value
baf1.push(baf1_value)

})
Expand Down
12 changes: 6 additions & 6 deletions js/cnvpytor/HDF5IndexedReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class HDF5Reader {
return chr_wig
}

async get_baf_signals(chrom, bin_size, signal_name){
async get_baf_signals(chrom, bin_size, signal_name, scaling_factor = -1){
/* return two list of dictionary*/
let chr_wig_1 = [];
let chr_wig_2 = [];
Expand All @@ -243,16 +243,16 @@ class HDF5Reader {
let max_value = Math.max(...bin_value);
const res = bin_value.indexOf(max_value);
let lh = Math.max(res / 200, 1 - res / 200);
chr_wig_1.push({chr:chrom, start: bin_idx*bin_size, end: (bin_idx+1) * bin_size, value: -2 * lh})
chr_wig_1.push({chr:chrom, start: bin_idx*bin_size, end: (bin_idx+1) * bin_size, value: scaling_factor * lh})
if(lh != 0.5){
chr_wig_2.push({chr:chrom, start: bin_idx*bin_size, end: (bin_idx+1) * bin_size, value: -2 *(1-lh)})
chr_wig_2.push({chr:chrom, start: bin_idx*bin_size, end: (bin_idx+1) * bin_size, value: scaling_factor *(1-lh)})
}
});
}
return [chr_wig_1, chr_wig_2]
}

async get_baf_signals_v2(chrom, bin_size, signal_name){
async get_baf_signals_v2(chrom, bin_size, signal_name, scaling_factor = -1){

/* return two list of dictionary*/
let chr_wig_1 = [];
Expand All @@ -262,9 +262,9 @@ class HDF5Reader {
let chrom_data = await chrom_dataset.to_array() //create_nested_array(value, shape)
chrom_data.forEach((lh, bin_idx) => {
if (!isNaN(lh)){
chr_wig_1.push({chr:chrom, start: bin_idx*bin_size, end: (bin_idx+1) * bin_size, value: -2 * ( 0.5 - lh )})
chr_wig_1.push({chr:chrom, start: bin_idx*bin_size, end: (bin_idx+1) * bin_size, value: scaling_factor * ( 0.5 - lh )})
if(lh != 0.5){
chr_wig_2.push({chr:chrom, start: bin_idx*bin_size, end: (bin_idx+1) * bin_size, value: -2 * ( 0.5 + lh )})
chr_wig_2.push({chr:chrom, start: bin_idx*bin_size, end: (bin_idx+1) * bin_size, value: scaling_factor * ( 0.5 + lh )})
}
}
});
Expand Down
11 changes: 6 additions & 5 deletions js/cnvpytor/cnvpytorTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class CNVPytorTrack extends TrackBase {
this.wigFeatures_obj[this.bin_size] = {}

let dataWigs;
if(this.config.cnv_caller == '2D'){

if(this.cnv_caller == '2D'){

dataWigs = await cnvpytor_obj.read_rd_baf('2D')

Expand Down Expand Up @@ -408,17 +409,17 @@ class CNVPytorTrack extends TrackBase {
if (this.defaultScale) {
if (this.signal_name == 'rd_snp') {
this.dataRange = {
min: this.config.min || this.dataRange.min || -2,
max: this.config.max || this.dataRange.max || 6
min: this.config.min || this.dataRange.min || -1,
max: this.config.max || this.dataRange.max || 5
}
} else if (this.signal_name == 'rd') {
this.dataRange = {
min: this.config.min || this.dataRange.min || 0,
max: this.config.max || this.dataRange.max || 6
max: this.config.max || this.dataRange.max || 5
}
} else if (this.signal_name == 'snp') {
this.dataRange = {
min: this.config.min || this.dataRange.min || -2,
min: this.config.min || this.dataRange.min || -1,
max: this.config.max || this.dataRange.max || 0
}
}
Expand Down
15 changes: 5 additions & 10 deletions js/cnvpytor/cnvpytorVCF.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,13 @@ class CNVpytorVCF {
// finalFeatureSet = this.readDepthMeanshift(avgbin)
var baf = this.formatDataStructure_BAF(avgbin, 'max_likelihood')
}else if(caller=='2D'){

let caller_obj = new combined_caller.CombinedCaller(avgbin, this.binSize)
let processed_bins = await caller_obj.call_2d()

finalFeatureSet = [processed_bins.binScore, [], processed_bins.segment_score]

var baf = caller_obj.formatDataStructure_BAF('max_likelihood')
var baf = caller_obj.formatDataStructure_BAF('max_likelihood', -1)
}


return [finalFeatureSet, baf]
}

Expand All @@ -108,8 +105,6 @@ class CNVpytorVCF {
return results
}



format_BAF_likelihood(wigFeatures) {
const results = []

Expand Down Expand Up @@ -155,8 +150,8 @@ class CNVpytorVCF {



formatDataStructure_BAF(wigFeatures, feature_column, scaling_factor = 2) {
/* Rescale the BAF level from 0:1 to -2:0*/
formatDataStructure_BAF(wigFeatures, feature_column, scaling_factor=-1) {
/* Rescale the BAF level from 0:1 to scaling_factpr:0*/
const baf1 = []
const baf2 = []
for (const [chr, wig] of Object.entries(wigFeatures)) {
Expand All @@ -168,10 +163,10 @@ class CNVpytorVCF {

let value = sample[feature_column]
if (value != 0.5){
baf2_value.value = -2 * (1 - value)
baf2_value.value = scaling_factor * (1 - value)
baf2.push(baf2_value)
}
baf1_value.value = -2 * value
baf1_value.value = scaling_factor * value
baf1.push(baf1_value)

}
Expand Down

0 comments on commit 8cdc14c

Please sign in to comment.