Package score

Source Code of score.CombineChipGene

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package score;

import fork.lib.base.file.FileName;
import fork.lib.base.file.io.txt.ReadTable;
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.DirectionalGenomicRegion;
import fork.lib.bio.anno.genomic.region.GenomicRegionsBuilder;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;

/**
*
* @author forksapien
*/
public class CombineChipGene {

public DecimalFormat df= new DecimalFormat("#.####");
   
protected File[] fs;

public HashMap<String, ArrayList<Double>> hm;
   
   
   
    public CombineChipGene(File[] fs) throws Exception{
        this.fs=fs;
        init();
    }
   
   
protected void init()throws Exception{
    hm=new HashMap<>();
    for( int i=0; i<fs.length ; i++ ){
        String[][] arr= new ReadTable(fs[i]).getTableAsArray();
        for( int j=0; j<arr.length ; j++ ){
            String[] r= arr[j];
            String dr= r[3]+"\t"+ r[0]+":"+Integer.parseInt(r[1])+"-"+ Integer.parseInt(r[2])+"\t"+ r[5].charAt(0);
            if(!hm.containsKey(dr)){
                hm.put(dr, new ArrayList<Double>());
            }
            if(hm.get(dr).size()==i){
                hm.get(dr).add(Double.parseDouble(r[4]));
            }
        }
    }
}



public void writeToFile(File out) throws IOException{
    out.getParentFile().mkdirs();
    BufferedWriter bw= new BufferedWriter(new FileWriter(out));
    String[] ks= new String[hm.keySet().size()];
    hm.keySet().toArray(ks);
    Arrays.sort(ks);
    for( int k=0; k<ks.length ; k++ ){
        String dr= ks[k];
        bw.write(dr);
        ArrayList<Double> vs= hm.get(dr);
        for( int i=0; i<vs.size() ; i++ ){
            bw.write("\t"+df.format(vs.get(i)));
        }
        bw.write("\n");
    }
    bw.close();
}
   
   
   
   
   
public static void main(String[] args) throws Exception { //debug
    //File dir= new File("G:/mystudy/phd/files");
    File dir= new File("/home/forksapien/mystudy/phd/files");
   
    File datd= new File(dir+"/data/chip/score");
    File od= new File(datd+"/combine");
   
    String[] regfs= new String[]{
        "sacCer1_gene_five_300.-150.bed",
        "sacCer1_gene_five_150.0.bed",
        "sacCer1_gene_five_0.150.bed",
        "sacCer1_gene_five_-150.300.bed",
        "sacCer1_gene_cds_300.300.bed",
        "sacCer1_gene_three_300.-150.bed",
        "sacCer1_gene_three_150.0.bed",
        "sacCer1_gene_three_0.150.bed",
        "sacCer1_gene_three_-150.300.bed"
    };
   
    String[] ms= new String[]{
        "htz1-anti660",
        //"k8ac",
        //"k10ac"
    };
   
   
   
    for( int i=0; i<regfs.length; i++ ){
        String reg= regfs[i];
        System.out.println(reg);
        File[] fs= new File[ms.length];
        for( int j=0; j<fs.length ; j++ ){
            String m= ms[j];
            fs[j]= new File(datd+"/"+m+"/"+m+"_"+reg);
        }
        CombineChipGene cb= new CombineChipGene(fs);
        cb.writeToFile(new File(od+"/comb_"+reg+".txt"));
    }
   
}
   
   
   
}






TOP

Related Classes of score.CombineChipGene

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.