Package data.cerevisiae.lee2007.pref

Source Code of data.cerevisiae.lee2007.pref.ToSeq

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package data.cerevisiae.lee2007.pref;

import fork.lib.base.file.FileName;
import fork.lib.base.file.management.Dirs;
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.bio.seq.FastaEntry;
import fork.lib.bio.seq.FastaExporter;
import fork.lib.bio.seq.GetSequenceFasta;
import fork.lib.bio.seq.NucleotideSequenceParser;
import java.io.File;
import java.util.Iterator;

/**
*
* @author man-mqbpjmg4
*/
public class ToSeq {
   
protected GenomicRegionsBuilder gb;
protected GetSequenceFasta get;
   
    public ToSeq(GenomicRegionsBuilder gb, GetSequenceFasta get)throws Exception {
        this.gb=gb;
        this.get=get;
    }
   
   
public void writeToFile(File out)throws Exception {
    FastaExporter fe= new FastaExporter(out);
    Iterator<GenomicRegion> it= gb.iterator();
    while(it.hasNext()){
        GenomicRegion gr= it.next();
        String seq= get.getSequence(gr);
        fe.appendEntry(new FastaEntry(gr.toUCSCFormat(), seq));
        String cseq = NucleotideSequenceParser.parseSequence(seq).complementary().toString();
        DirectionalGenomicRegion cgr= new DirectionalGenomicRegion(gr.chr, '-', (int)gr.low, (int)gr.high);
        fe.appendEntry(new FastaEntry( cgr.toUCSCFormat(), cseq));
    }
    fe.close();
}


public static void main(String[] args) throws Exception { //debug
    File dir= Dirs.getFile("dir");
    File d = new File(dir+"/other_datasets/lee_2007_nucleosome/pref");
    File od= new File(d+"/seq");
   
    GetSequenceFasta get= new GetSequenceFasta(new File(dir+"/anno/genomes/sacCer1/sacCer1.fa"));
   
    for( int i=0; i<10; i++ ){
        File f= new File(d+"/bin_"+i+".bed");
        GenomicRegionsBuilder gb= new BedReader(f).getGenomicRegionsBuilder();
        ToSeq tt= new ToSeq(gb, get);
        File of= new File(od+"/seq_"+FileName.getBaseName(f)+".fasta");
        tt.writeToFile(of);
    }
   
   
   
   
   
   
}
   
   
   
}
TOP

Related Classes of data.cerevisiae.lee2007.pref.ToSeq

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.