Package data.cerevisiae.region.scan

Source Code of data.cerevisiae.region.scan.ScanIntra

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

import fork.lib.base.file.FileName;
import fork.lib.bio.anno.genomic.BedGraphBuffer;
import fork.lib.bio.anno.genomic.BedGraphReader;
import fork.lib.bio.anno.genomic.BedReader;
import fork.lib.bio.anno.genomic.LandscapeBuffer;
import fork.lib.bio.anno.genomic.LandscapeBuilder;
import fork.lib.bio.anno.genomic.LandscapeScoring;
import fork.lib.bio.anno.genomic.LandscapeScoringResultEntry;
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.advanced.linearalgebra.Vector;
import fork.lib.math.algebra.elementary.set.continuous.Region;
import fork.lib.math.algebra.elementary.set.continuous.RegionException;
import fork.lib.math.applied.buffer.Landscape2DBuffer;
import java.io.File;
import java.util.ArrayList;
import data.cerevisiae.inhouse.a_score.ScoreChipGene;

/**
*
* @author forksapien
*/
public class ScanIntra {
   
   
   
protected GenomicRegionsBuilder gb;
protected LandscapeBuffer lb;
   
public double thr= 0;
public int intv= 50;
public int side5 = 150;
public int side3 = 150;
public int gap= 51;

public double totarea=0;
public GenomicRegionsBuilder gbout= new GenomicRegionsBuilder();



   
    public ScanIntra(GenomicRegionsBuilder gb, LandscapeBuffer lb) throws Exception{
        this.gb= gb;
        this.lb=lb;
       
    }
   
   
protected void start() throws Exception{
    LandscapeScoring ls= new LandscapeScoring(lb, gb){
        protected double[] score(ArrayList<Region> bufs, GenomicRegion gr) throws RegionException{
            return Landscape2DBuffer.getLandscape(bufs, gr);
        }
    };
    ArrayList<LandscapeScoringResultEntry> ress= ls.getResultEntries();
    for( int i=0; i<ress.size() ; i++ ){
        LandscapeScoringResultEntry res= ress.get(i);
        DirectionalGenomicRegion gr= (DirectionalGenomicRegion)res.gr;
        double[] vs= res.scores;
        int slow= gr.isOnForwardStrand() ? side5: side3,
                shigh= gr.isOnForwardStrand() ? side3 : side5;
        if(vs.length >  (slow+shigh)){
            int left= slow;
            while( true ){
                if(left>= (vs.length-shigh)){
                    break;
                }
                int right= (left+intv)<vs.length ? left+intv : vs.length-1;
                double area= 0;
                for( int k=left; k<=right ; k++ ){
                    area+= vs[k];
                }
                double na= area/ (right-left+1);
                if(na> thr){
                    DirectionalGenomicRegion grr= new DirectionalGenomicRegion(
                            gr.chr, gr.strand, (int)gr.low+left, (int)gr.low+right);
                    grr.attr= gr.attr;
                   
                    gbout.add(grr);
                    totarea+= area;
                }
                left= right+1;
            }
        }
    }
    gbout.join(gap);
}
   





public void writeToFile(File out) throws Exception{
    LandscapeScoring ls= new LandscapeScoring(lb, gbout);
    LandscapeScoringResultEntry.writeToBedFile(ls.getResultEntries(), out);
}










  
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 regf= new File(dir+"/anno/sgdGene_sacCer1.bed"); String org ="sacCer1";
    File regf= new File(dir+"/anno/xu_2009_orfs.bed"); String org ="sacCer1-xu";
   
    int s5= 300; int s3= 0; double thr= 10; int gap= 51;
    String samp=  "742";

   
   
    File datf= new File(dir+"/data/chip-seq/norm/norm_"+samp+".wig");
   

    LandscapeBuffer lb= new BedGraphBuffer(datf);
    GenomicRegionsBuilder gb= new BedReader(regf).getGenomicRegionsBuilder();

   
   
    ScanIntra si = new ScanIntra(gb, lb);
    si.side5= s5;
    si.side3= s3;
    si.thr= thr;
    si.gap=gap;
    si.start();
    File of= new File("out/score/set/"+org+"/scan/intra_"+s5+"_"+s3+"_"+thr+"_"+gap+".bed");
    System.out.println(of);
    si.writeToFile(of);
   
}
   
   


   
   
   
}



TOP

Related Classes of data.cerevisiae.region.scan.ScanIntra

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.