/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package prop.clas;
import fork.lib.base.file.FileName;
import fork.lib.base.file.management.Dirs;
import fork.lib.bio.anno.genomic.BedAttribute;
import fork.lib.bio.anno.genomic.BedExporter;
import fork.lib.bio.anno.genomic.BedReader;
import fork.lib.bio.anno.genomic.region.DirectionalGenomicRegion;
import fork.lib.bio.anno.genomic.region.GenomicRegion;
import fork.lib.bio.anno.genomic.region.GenomicRegionsBuilder;
import fork.lib.math.algebra.elementary.set.continuous.Region;
import fork.lib.math.applied.stat.Distribution;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
/**
*
* @author forksapien
*/
public class ClassOrientation {
public static double thr= 300;
public static File dir= Dirs.getFile("dir"),
anno= new File(dir+"/anno/xu_2009_orfs.bed");
protected static void add(GenomicRegion tar, GenomicRegion ref, String tag){
double dis= tar.distanceFrom(ref);
if(dis > thr){
tag= tag+"1";
}else if(dis>0){
tag= tag+"01";
}else{
tag+="00";
}
tar.setValue(Double.parseDouble(tag));
}
public static void main(String[] args) throws Exception { //debug
File dir= Dirs.getFile("dir");
File od= new File(dir+"/anno/bed/sacCer1-xu/orient");
File f= new File(dir+"/anno/xu_2009_orfs.bed");
GenomicRegionsBuilder gb= new BedReader(f).getGenomicRegionsBuilder();
GenomicRegionsBuilder gbout= new GenomicRegionsBuilder();
String[] chrs= gb.getChromosomeList();
for(int i=0; i<chrs.length ; i++){
String chr= chrs[i];
ArrayList<Region> regs= gb.getRegionsForChromosome(chr);
for(int j=0; j<regs.size() ; j++){
DirectionalGenomicRegion dr= (DirectionalGenomicRegion)regs.get(j);
if(dr.isOnForwardStrand()){
if( j== regs.size()-1 ){
dr.setValue(331);
}else{
DirectionalGenomicRegion drn= (DirectionalGenomicRegion) regs.get(j+1);
if(drn.isOnForwardStrand()){
add(dr, drn, "35");
}else{
add(dr, drn, "33");
}
}
}else{
if(j==0){
dr.setValue(331);
}else{
DirectionalGenomicRegion drn= (DirectionalGenomicRegion) regs.get(j-1);
if(drn.isOnReverseStrand()){
add(dr, drn, "35");
}else{
add(dr, drn, "33");
}
}
}
gbout.add(dr);
}
}
gbout.writeToFileBed(new File(od+"/orient3.bed"));
}
}