/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package data.human.test.trsc.time0;
import fork.lib.base.file.FileName;
import fork.lib.base.file.management.Dirs;
import fork.lib.bio.anno.genomic.BedAttribute;
import fork.lib.bio.anno.genomic.BedExporter;
import fork.lib.bio.anno.genomic.BedReader;
import fork.lib.bio.anno.genomic.region.GenomicRegion;
import fork.lib.bio.anno.genomic.region.GenomicRegionsBuilder;
import fork.lib.bio.anno.genomic.region.GenomicRegionsComparator;
import fork.lib.bio.anno.genomic.region.GenomicRegionsCrossover;
import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
/**
*
* @author man-mqbpjmg4
*/
public class LinkChip {
protected GenomicRegionsBuilder gb, gbcomp;
public LinkChip(GenomicRegionsBuilder gb, GenomicRegionsBuilder gbref)throws Exception {
this.gb=gb;
this.gbcomp=gbref;
}
public void writeToFile(File out)throws Exception {
GenomicRegionsCrossover gc= new GenomicRegionsComparator(gb, gbcomp).getCrossover();
HashSet<GenomicRegion> allrs= new HashSet<>();
Iterator<GenomicRegion> it= gc.both.iterator();
while(it.hasNext()){
allrs.add( it.next() );
}
it= gb.iterator();
while(it.hasNext()){
GenomicRegion gr= it.next();
if(allrs.contains(gr)){
gr.setValue(1);
}
}
new BedExporter(gb).writeToFile(out);
}
public static void main(String[] args) throws Exception { //debug
File dir= Dirs.getFile("dir");
File d= new File(dir+"/data/human_magnus/h2az/norm/peak");
File od= new File(d+"/link");
File compf= new File(dir+"/other_datasets\\statham2014_mcf7-mods\\norm\\peaks\\locate\\ensGene_hg19_exon/locate_peak_norm_wig_mcf7_h3k4me1_SRR1282220_hg19.bed");
//File compf= new File(dir+"/other_datasets\\statham2014_mcf7-mods\\norm\\peaks\\locate\\ensGene_hg19_exon/locate_peak_norm_wig_mcf7_h3k27ac_SRR1282218_hg19.bed");
//File compf= new File(dir+"/other_datasets/statham2014_mcf7-mods/GSM1383850_MCF7_NDR_locate.bed");
GenomicRegionsBuilder gbcomp= new BedReader(compf).getGenomicRegionsBuilder();
String[] ts= new String[]{
"0"
};
for( int i=0; i<ts.length; i++ ){
String t= ts[i];
File f= new File(d+"/peak_norm_wig_mcf7_chip-h2az_time-"+t+"_hg19.bed");
GenomicRegionsBuilder gb= new BedReader(f).getGenomicRegionsBuilder();
String tag= FileName.getBaseName(compf);
LinkChip ll= new LinkChip(gb, gbcomp);
File out= new File(od+"/"+tag+"/time-"+t+"_"+tag+".bed");
ll.writeToFile(out);
}
}
}