Hello everyone: There is a problem puzzled me recently,I have got every individual CNV output by the tool of CNVnator,and next I want to merge all outputs to a file(if two CNVs have overlap >0.5 can be considered to a common one), but I don't know how to merge these files.I have tried the VCFtools( CNVnator has a perl script which can switch the out to VCF format),bcftools,bedtools ,but there is no a tool can really solve my question(some tool would discard these no-overlap CNVs),so who can give me some suggestions to solve this hard trouble? this is my output:
# chr start end type
chr1 7967601 7984800 deletion
chr1 9441201 9447200 duplication
chr1 10546001 10553200 deletion
chr1 10822001 10830400 deletion
2 answers
a 'stupid' solution using javascript ?
// following array is generated with awk '{printf("{\"chrom\":\"%s\",\"start\":%s,\"end\":%s,\"type\":\"%s\"},\n",$1,$2,$3,$4);}' your.bed
var segments=[
{"chrom":"chr1","start":7967601,"end":7984800,"type":"duplication"},
{"chrom":"chr1","start":7967602,"end":7984810,"type":"duplication"},
{"chrom":"chr1","start":7967602,"end":7967603,"type":"duplication"},
{"chrom":"chr1","start":1,"end":100,"type":"duplication"},
{"chrom":"chr1","start":10546001,"end":10553200,"type":"deletion"},
{"chrom":"chr1","start":10546101,"end":10553000,"type":"deletion"}
]
var done=false;
while(done==false)
{
done=true;
var i=0;
while(done && i + 1< segments.length)
{
var j = i+1;
while(j < segments.length)
{
var segi = segments[i];
var segj = segments[j];
if( segi.chrom != segj.chrom) {++j; continue;}
if( segi.type != segj.type) {++j; continue;}
if( segj.end <= segi.start) {++j; continue;}
if( segj.start >= segi.end) {++j; continue;}
var overlap_len = 1.0 * ( Math.min(segi.end,segj.end) - Math.max(segi.start,segj.start) );
var leni = 1.0* (segi.end - segi.start);
if( overlap_len / leni < 0.5) {++j; continue;}
var lenj = 1.0* (segj.end - segj.start);
if( overlap_len / lenj < 0.5) {++j; continue;}
segments.splice(j,1);
segments[i]={
"chrom":segi.chrom,
"start": Math.min(segi.start,segj.start),
"end": Math.max(segi.end,segj.end),
"type":segi.type
}
done=false;
}
i++;
}
}
for(var i in segments)
{
var segi = segments[i];
print(segi.chrom+"\t"+segi.start+"\t"+segi.end+"\t"+segi.type);
}
invoke with jjs or in a firefox scratchad
$ jjs script.js
chr1 7967601 7984810 duplication
chr1 7967602 7967603 duplication
chr1 1 100 duplication
chr1 10546001 10553200 deletion
ok,thank you very much .and I will try it .
Log in to answer this question.
I met the same problem. Have you solve it?
我也遇到了相同的问题,请问你们解决了吗?
hi, I also met the same problem ...