/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package data.human.inhouse.chippeak.ap;
import fork.lib.base.file.management.Dirs;
import fork.lib.bio.anno.genomic.BedExporter;
import fork.lib.bio.anno.genomic.BedReader;
import fork.lib.bio.anno.genomic.region.DirectionalGenomicRegion;
import fork.lib.bio.anno.genomic.region.GenomicRegion;
import fork.lib.bio.anno.genomic.region.GenomicRegionsBuilder;
import java.io.File;
import java.util.Iterator;
/**
*
* @author muxin gu
*/
public class GenerateSideRegion {
protected GenomicRegionsBuilder gbout= new GenomicRegionsBuilder();
protected static int side= 200;
public GenerateSideRegion(GenomicRegionsBuilder gb)throws Exception{
Iterator<GenomicRegion> it= gb.iterator();
while(it.hasNext()){
DirectionalGenomicRegion gr= (DirectionalGenomicRegion)it.next();
DirectionalGenomicRegion gro;
if(gr.isOnForwardStrand()){
gro= new DirectionalGenomicRegion(gr.chr, gr.strand, (int)gr.high-side, (int)gr.high+side);
}else{
gro= new DirectionalGenomicRegion(gr.chr, gr.strand, (int)gr.low-side, (int)gr.low+side);
}
gro.setID(gr.getID());
gro.setValue(gr.getValue());
gbout.add(gro);
}
}
public void writeToFile(File out)throws Exception{
new BedExporter(gbout).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/macs/merge/extract");
File f= new File(d+"/5_locate_ensGene_hg19_exon.bed");
File out = new File(d+"/side-right_"+ Integer.toString(side)+"_"+f.getName() );
GenomicRegionsBuilder gb= new BedReader(f).getGenomicRegionsBuilder();
GenerateSideRegion gg= new GenerateSideRegion(gb);
gg.writeToFile(out);
}
}