/*
* 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.cerevisiae.histmod.magraner2014_histmods;
import fork.lib.base.collection.Table;
import fork.lib.base.file.FileName;
import fork.lib.base.file.io.txt.ReadTable;
import fork.lib.base.file.management.Dirs;
import fork.lib.bio.anno.genomic.region.GenomicRegion;
import fork.lib.bio.data.microarraychip.ChipArrayParser;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
/**
*
* @author man-mqbpjmg4
*/
public class ProcessData {
public static void main(String[] args) throws Exception { //debug
File dir= Dirs.getFile("dir");
File d= new File(dir+"/other_datasets/magraner2014_histmods");
File dd= new File(d+"/data");
File od= new File(dd+"/wig");
File pf= new File(d+"/GPL4130-5632.txt");
File[] afs= dd.listFiles();
HashMap<String, GenomicRegion> idreg= new HashMap<>();
ReadTable rt= new ReadTable(pf);
rt.setSkipRows(0);
Table<String> tab= rt.getTable();
for( int i=0; i<tab.getRowNumber(); i++ ){
ArrayList<String> r= tab.getRow(i);
String reg= r.get(9);
if(!reg.equals("")){
GenomicRegion gr= GenomicRegion.parseGenomicRegoinUCSC(reg);
idreg.put(r.get(0), gr);
//System.out.println(r.get(0)+" "+ gr.toUCSCFormat());
}
}
for( int i=0; i<afs.length; i++ ){
File af= afs[i];
if(FileName.getExt(af).equals("txt")){
ReadTable rtaf= new ReadTable(af);
rtaf.setSkipRows(0);
HashMap<String,String> idvals= rtaf.getHashMap(0, 1);
HashMap<String,Double> idval= new HashMap<>();
Iterator<String> it= idvals.keySet().iterator();
while(it.hasNext()){
String id= it.next();
idval.put(id, Double.parseDouble(idvals.get(id)));
}
ChipArrayParser cp = new ChipArrayParser(idreg, idval);
File out= new File(od+"/"+FileName.getBaseName(af)+".wig");
cp.writeToFile(out, FileName.getBaseName(af));
}
}
}
}