/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package data.cerevisiae.region.scan;
import fork.lib.base.file.io.txt.ReadTable;
import fork.lib.base.file.management.Dirs;
import fork.lib.bio.anno.genomic.BedGraphReader;
import fork.lib.bio.anno.genomic.BedReader;
import fork.lib.bio.anno.genomic.LandscapeBuffer;
import fork.lib.bio.anno.genomic.LandscapeScoring;
import fork.lib.bio.anno.genomic.LandscapeScoringResultEntry;
import fork.lib.bio.anno.genomic.UCSCRegionParser;
import fork.lib.bio.anno.genomic.region.GenomicRegion;
import fork.lib.bio.anno.genomic.region.GenomicRegionsBuilder;
import fork.lib.math.algebra.elementary.set.continuous.Region;
import fork.lib.math.algebra.elementary.set.continuous.RegionException;
import fork.lib.math.applied.buffer.Landscape2DBuffer;
import java.io.File;
import java.util.ArrayList;
/**
*
* @author forksapien
*/
public class AntisenseFraction {
protected File f;
protected LandscapeBuffer lb;
protected GenomicRegionsBuilder gb;
public AntisenseFraction(File f, LandscapeBuffer lb) throws Exception{
this.f=f;
this.lb=lb;
init();
}
private void init() throws Exception{
gb= new GenomicRegionsBuilder();
ReadTable rt= new ReadTable(f);
String[][] arr= rt.getTableAsArray();
for( int i=0; i<arr.length ; i++ ){
String [] r= arr[i];
GenomicRegion gr= UCSCRegionParser.parseGenomicRegion(r[4]).getExtendedRegion(-50, -50);
double vf= Double.parseDouble(r[6]);
double vt= Double.parseDouble(r[7]);
double d= vt-vf;
double rat= vt/vf;
if(rat>2 && d>7){
gb.add(gr);
}
}
LandscapeScoring ls= new LandscapeScoring(lb, gb){
protected double[] score(ArrayList<Region> bufs, GenomicRegion gr) throws RegionException{
return new double[]{Landscape2DBuffer.getArea(bufs, gr)};
}
};
double sum= LandscapeScoringResultEntry.toDistribution(ls.getResultEntries(), 0).sum();
System.out.println(gb.size());
System.out.println(sum);
}
public static void main(String[] args) throws Exception {
File dir= Dirs.getFile("dir");
File f= new File("out/score/set/sacCer1-xu/scan/linkAnti_intra_300_0_10_51.bed");
String samp= "742";
File datf= new File(dir+"/data/chip-seq/norm/norm_"+samp+".wig");
LandscapeBuffer lb= new BedGraphReader(datf).getLandscapeBuilder();
AntisenseFraction aa= new AntisenseFraction(f, lb);
}
}