Package data.cerevisiae.vanbakel2013

Source Code of data.cerevisiae.vanbakel2013.SelectAndJoin

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

import fork.lib.base.collection.NamedTable;
import fork.lib.base.file.FileName;
import fork.lib.base.file.io.txt.ReadTable;
import fork.lib.base.file.management.Dirs;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author muxin gu
*/
public class SelectAndJoin {
   
public static double thr=0.3;
public static File dir= Dirs.getFile("dir"),
        ref= new File(dir+"/anno/xu_2009_orfs.bed"),
        nf= new File(dir+"/anno/sgd_name.bed");
public static NamedTable<String,String, String> tab;
static{
    try {
        tab = new NamedTable<>();
    } catch (Exception ex) {
    }
}

   
public static void initRows(File f) throws IOException{
    ReadTable rt= new ReadTable(f);
    String[] rns= rt.getColumn(3);
    for(int j=0; j<rns.length ; j++){
        String rn= rns[j];
        if(!tab.containsRow(rn)){
            tab.appendEmptyRow(rn);
        }
    }
    String[][] arr= rt.getTableAsArray();
    tab.appendEmptyColumn("pos");
    for(int i=0; i<arr.length ; i++){
        String[] r= arr[i];
        String pos= r[0]+":"+r[1]+"-"+r[2];
        tab.setValueAt(pos, r[3], "pos");
    }
}
   
   
public static void addBedFile(File f) throws IOException{
    String cn= FileName.getBaseName(f);
    tab.appendEmptyColumn(cn);
    ReadTable rt= new ReadTable(f);
    String[] rns= rt.getColumn(3);
    String[] vs= rt.getColumn(4);
    for(int j=0; j<rns.length ; j++){
        String rn= rns[j];
        String v= vs[j];
        if(tab.containsRow(rn)){
            tab.setValueAt(v, rn, cn);
        }
    }
}

public static void addNameBedFile(File f) throws IOException{
    addBedFile(f);
    String cn= FileName.getBaseName(f);
    for(int i=0; i<tab.getRowNames().size() ; i++){
        String rn= tab.getRowNames().get(i);
        String v= tab.getValueAt(rn, cn);
        if(v==null){
            tab.setValueAt(rn, rn, cn);
        }
    }
}


public static void addHtz1(File f)throws Exception{
    String cn= FileName.getBaseName(f);
    tab.appendEmptyColumn(cn);
    ReadTable rt= new ReadTable(f);
    String[] rns= rt.getColumn(3);
    String[] vs= rt.getColumn(4);
    for( int i=0; i<rns.length; i++ ){
        String rn= rns[i];
        double v= Double.parseDouble(vs[i]);
        String tv;
        if(v>0.6){
            tv="1";
        }else if(v<-0.6){
            tv="-1";
        }else{
            tv="0";
        }
        tab.setValueAt(tv, rn, cn);
    }
}

public static void addFile(File f)throws Exception{
    String cn= FileName.getBaseName(f);
    tab.appendEmptyColumn(cn);
    ReadTable rt= new ReadTable(f);
    String[] rns= rt.getColumn(3);
    String[] vs= rt.getColumn(4);
    for( int i=0; i<rns.length; i++ ){
        String rn= rns[i];
        double v= Double.parseDouble(vs[i]);
        String tv;
        if(v>thr){
            tv="1";
        }else if(v<-thr){
            tv="-1";
        }else{
            tv="0";
        }
        tab.setValueAt(tv, rn, cn);
    }
}


   
   
public static void main(String[] args) throws Exception { //debug
    File dir= Dirs.getFile("dir");


    //String tag= "sense"; double thr=0.3;
    String tag= "antisense"; double thr=0.15;


    SelectAndJoin.thr=thr;
    initRows(ref);
    addNameBedFile(nf);
   
    File d= new File(dir+"/other_datasets/vanbakel_2013/score/score_"+tag);
   
    addHtz1(new File(d+"/"+tag+"_log-fc_htz1.bed"));
    File[] fs= d.listFiles();
    for( int i=0; i<fs.length; i++ ){
        File f= fs[i];
        if(FileName.getExt(f).equals("bed")){
            String fn= FileName.getBaseName(f);
            if(fn.indexOf("htz1")==-1 && fn.indexOf("tet")==-1){
                addFile(f);
            }
        }
    }


    File od= new File(d+"/join");
    File out= new File(od+"/"+tag+"_join.txt");
    tab.writeToFile(out);
   
   
}
   
   
   
   
   
   
}
TOP

Related Classes of data.cerevisiae.vanbakel2013.SelectAndJoin

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.