/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package data.cerevisiae.histmod.guillemette2011;
import fork.lib.base.file.FileName;
import fork.lib.base.file.io.txt.*;
import fork.lib.base.file.management.Dirs;
import fork.lib.bio.anno.genomic.BedGraphExporter;
import fork.lib.bio.anno.genomic.LandscapeBuilder;
import fork.lib.math.algebra.elementary.set.continuous.Region;
import java.io.File;
import java.util.ArrayList;
/**
*
* @author muxin gu
*/
public class ToWig {
public static void main(String[] args) throws Exception { //debug
File dir= Dirs.getFile("dir");
File d= new File(dir+"/other_datasets/guillemette_2011_h4k3me3-ac");
//File f= new File(d+"/GSM675135_WT_H3K4me3_on_H3.wig"), out=new File(d+"/h3k4me3_guillemette2011.wig");
File f= new File(d+"/GSM675134_WT_H3K4ac_on_H3.wig"), out=new File(d+"/h3k4ac_guillemette2011.wig");
MarkReader mr= new MarkReader(f, "variableStep");
MarkEntry en;
LandscapeBuilder lb= new LandscapeBuilder();
while((en=mr.nextEntry())!=null){
String chr= en.tit.split("chrom=")[1];
if(!chr.equals("chrM")){
ArrayList<String> rs= en.chunk;
int ps= 1;
for( int i=0; i<rs.size(); i++ ){
String l=rs.get(i);
if(l.length()>0 && l.charAt(0)!='#'){
String[] ss= l.split("\t");
if(ss.length==2){
int p= Integer.parseInt(ss[0]);
double v= Double.parseDouble(ss[1]);
if(p<ps){
System.out.println(chr+" "+ p+" "+ v);
}
Region reg= new Region(ps, p);
reg.setAttribute(v);
lb.add(chr, reg);
ps= p+1;
}
}
}
}
}
BedGraphExporter be =new BedGraphExporter(lb);
be.param().tit= FileName.getBaseName(out);
be.writeToFile(out);
}
}