/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package data.cerevisiae.inhouse.chip;
import fork.lib.base.file.FileName;
import fork.lib.base.file.management.Dirs;
import fork.lib.bio.anno.genomic.BedGraphExporter;
import fork.lib.bio.anno.genomic.BedGraphReader;
import fork.lib.bio.anno.genomic.BedReader;
import fork.lib.bio.anno.genomic.LandscapeBuilder;
import fork.lib.bio.anno.genomic.region.GenomicRegionsBuilder;
import fork.lib.math.algebra.elementary.set.continuous.Region;
import java.io.File;
import java.util.ArrayList;
/**
*
* @author forksapien
*/
public class ChipChipRemoveExtreme {
protected LandscapeBuilder lb;
protected GenomicRegionsBuilder gbchr;
public ChipChipRemoveExtreme(LandscapeBuilder lb, GenomicRegionsBuilder gbchr)throws Exception{
this.lb=lb;
this.gbchr= gbchr;
}
public void writeToFile(File out)throws Exception{
LandscapeBuilder lbout= new LandscapeBuilder();
String[] chrs= gbchr.getChromosomeList();
for(int i=0; i<chrs.length ; i++){
String chr= chrs[i];
if(lb.containsChromosome(chr)){
ArrayList<Region> rs= lb.getLandscape2DForChromosome(chr).getRegions();
double lim= gbchr.getRegionsForChromosome(chr).get(0).high;
for(int j=0; j<rs.size() ; j++){
Region r= rs.get(j);
if( r.lowerThan(lim) ){
lbout.add(chr,r);
}
}
}
}
BedGraphExporter be= new BedGraphExporter(lbout);
be.param().tit= FileName.getBaseName(out);
be.writeToFile(out);
}
public static void main(String[] args) throws Exception{ //debug
File dir= Dirs.getFile("dir");
File d= new File(dir+"/data/chip/norm");
File od= new File(d+"/for_ucsc");
String[] fs= new String[]{
"htz1",
"k8ac",
"k10ac",
"k14ac"
};
GenomicRegionsBuilder gb= new BedReader(new File(dir+"/anno/sacCer1_chr.bed")).getGenomicRegionsBuilder();
for(int i=0; i<fs.length ; i++){
String ty= fs[i];
File f= new File(d+"/norm_"+ty+".wig");
ChipChipRemoveExtreme cc= new ChipChipRemoveExtreme(
new BedGraphReader(f).getLandscapeBuilder(), gb
);
File out= new File(od+"/ucsc_"+f.getName());
cc.writeToFile(out);
}
}
}