Ejemplo n.º 1
0
def rawsort(ifile,sort_ofile,gfile,format,step=10,suppress=False,buffer=None):
    tm=time()
    if format=='wig':
        print('\nconverting',ifile,'...')
        raw_ofile=sort_ofile[:-3]+'raw.wiq'
        wg=Wig(file=ifile,gfile=gfile,step=step,suppress=suppress)
        wg.ajust_size(gfile=gfile)
        wg.save(file=raw_ofile,format="wiq",step=step,suppress=suppress)
        print('time cost:',time()-tm)
        tm=time()
    else:raw_ofile=ifile
    
    print('\nsorting',raw_ofile,'...')
    temp=ifile[:-3]+'temp'
    while os.path.isdir(temp):temp=temp+'.temp'
    os.mkdir(temp)
    if buffer!=None:cmd='sort -r -n -s -k1 -k2 -o '+sort_ofile+' --buffer-size '+str(buffer)+' --temporary-directory '+str(temp)+' '+raw_ofile
    else:cmd='sort -r -n -s -k1 -k2 -o '+sort_ofile+' --temporary-directory '+str(temp)+' '+raw_ofile
    os.system(cmd)
    if format=='wig':
        print('Removing ',raw_ofile,'...')
        os.system('rm '+raw_ofile)
    print('removing',temp)
    os.system('rm '+str(temp)+' -r')
    print('time cost:',time()-tm)
Ejemplo n.º 2
0
def rawsort(ifile,sort_ofile,gfile,format,step=10,suppress=False,buffer=None):
    tm=time()
    if format=='wig':
        print '\nconverting',ifile,'...'
        raw_ofile=sort_ofile[:-3]+'raw.wiq'
        wg=Wig(file=ifile,gfile=gfile,step=step,suppress=suppress)
        wg.ajust_size(gfile=gfile)
        wg.save(file=raw_ofile,format="wiq",step=step,suppress=suppress)
        print 'time cost:',time()-tm
        tm=time()
    else:raw_ofile=ifile
    
    print '\nsorting',raw_ofile,'...'
    temp=ifile[:-3]+'temp'
    while os.path.isdir(temp):temp=temp+'.temp'
    os.mkdir(temp)
    if buffer!=None:cmd='sort -r -n -s -k1 -k2 -o '+sort_ofile+' --buffer-size '+str(buffer)+' --temporary-directory '+str(temp)+' '+raw_ofile
    else:cmd='sort -r -n -s -k1 -k2 -o '+sort_ofile+' --temporary-directory '+str(temp)+' '+raw_ofile
    os.system(cmd)
    if format=='wig':
        print 'Removing ',raw_ofile,'...'
        os.system('rm '+raw_ofile)
    print 'removing',temp
    os.system('rm '+str(temp)+' -r')
    print 'time cost:',time()-tm
Ejemplo n.º 3
0
Archivo: wiq.py Proyecto: cschu/DANPOS3
def changevalue(ifile,
                ref,
                ofile,
                gfile,
                step=10,
                suppress=False,
                buffer=None):
    from random import randint
    if ifile != ref: print('\nnormalizing', ifile, '...')
    else: print('\nsaving reference ...')
    tm = time()
    fi, fr = open(ifile), open(ref)
    wg = Wig(step=step, gfile=gfile)
    for line in fi:
        col = line.split()
        rcol = fr.readline().split()
        if len(rcol) == 0: rcol = [0.0]
        cr, pos, vl = col[2], int(col[3]) / step, float(rcol[0])
        wg.data[cr][pos] = vl
    n = 0
    for line in fr:
        n += 1
    if n > 0:
        print(
            'Warning: the input genome size is smaller than the reference genome size by',
            n, 'wiggle steps!')
    wg.save(ofile, suppress=suppress)
    print('time cost:', time() - tm)
Ejemplo n.º 4
0
def changevalue(ifile,ref,ofile,gfile,step=10,suppress=False,buffer=None):
    from random import randint
    if ifile!=ref:print '\nnormalizing',ifile,'...'
    else:print '\nsaving reference ...'
    tm=time()
    fi,fr=open(ifile),open(ref)
    wg=Wig(step=step,gfile=gfile)
    for line in fi:
        col=line.split()
        rcol=fr.readline().split()
        if len(rcol)==0:rcol=[0.0]
        cr,pos,vl=col[2],int(col[3])/step,float(rcol[0])
        wg.data[cr][pos]=vl
    n=0
    for line in fr:n+=1
    if n>0:print 'Warning: the input genome size is smaller than the reference genome size by',n,'wiggle steps!'
    wg.save(ofile,suppress=suppress)
    print 'time cost:',time()-tm