Package data.cerevisiae.harbison

Source Code of data.cerevisiae.harbison.Harbison2004$HClassifier

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

import common.inspect.Classifier;
import common.inspect.GeneSet;
import fork.lib.base.Print;
import fork.lib.base.file.io.txt.ReadTable;
import fork.lib.base.file.management.Dirs;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

/**
*
* @author forksapien
*/
public class Harbison2004 {
   
protected File f;

protected HashMap<String, Integer> idCol= new HashMap<>();
protected String [] ids;
protected double[][] vss;


   
   
    public Harbison2004(File f) throws Exception{
        this.f=f;
        init();
    }
   
   
   
protected void init() throws Exception{
    ReadTable rt= new ReadTable(f);
    String[][] arr= rt.getTableAsArray();
    String[] cns= arr[0];
    for(int i=1; i<cns.length ; i++){
        String n= cns[i];
        n= n.replace("_YPD", "");
        n= n.replace("(", "");
        n= n.replace(")", "");
        n= n.replace(" ", "_");
        n= n.toUpperCase();
        idCol.put(n, i-1);
    }
    ids= new String[arr.length-1];
    for(int i=1; i<arr.length ; i++){
        ids[i-1]= arr[i][0];
    }
    vss= new double[arr.length-1][];
    for(int i=1; i<arr.length ; i++){
        String[] ss= arr[i];
        vss[i-1]= new double[ss.length-1];
        for(int j=1; j<ss.length ; j++){
            Double v= Double.parseDouble(ss[j]);
            if(v.isNaN()){
                v= 1d;
            }
            vss[i-1][j-1]= v;
        }
    }
}



public String[] getTranscriptionFactors(){
    String[] ret= idCol.keySet().toArray(new String[idCol.size()]);
    Arrays.sort(ret);
    return ret;
}

public Classifier getClassifierForTF(String tf)throws Exception{
    tf= tf.toUpperCase();
    final int col= idCol.get(tf);
    Classifier ret= new HClassifier(tf, col);
    return ret;
}



class HClassifier extends Classifier{
   
protected int col;

    public HClassifier(String tit, int col) throws Exception{
        super(tit);
        this.col=col;
        init();
    }
   
    public void init() throws Exception{
        sets.add(new GeneSet(tit+"_y"));
        sets.add(new GeneSet(tit+"_n"));
        for(int i=0; i<vss.length ; i++){
            double v= vss[i][col];
            String id= ids[i];
            if(v<0.001){
                sets.get(0).add(id);
            }else{
                sets.get(1).add(id);
            }
        }
    }
}



public static void main(String[] args) throws Exception{ //debug
    File dir= Dirs.getFile("dir");
    Harbison2004 hh= new Harbison2004(new File(dir+"/other_datasets/harbison_2004/pvalbygene_forpaper_abbr.txt"));

    GeneSet set= hh.getClassifierForTF("xbp1").geneSets().get(0);
    Print.collection(set);
   
}
   
   
   
}
TOP

Related Classes of data.cerevisiae.harbison.Harbison2004$HClassifier

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.