Esempio n. 1
0
def doManQQ(input_fname,
            chrom_col,
            offset_col,
            pval_cols,
            title,
            grey,
            ctitle,
            outdir,
            beTidy=False):
    """ 
    we may have an interval file or a tabular file - if interval, will have chr1... so need to adjust
    to chrom numbers
    draw a qq for pvals and a manhattan plot if chrom/offset <> 0
    contains some R scripts as text strings - we substitute defaults into the calls
    to make them do our bidding - and save the resulting code for posterity
    this can be called externally, I guess...for QC eg?
    """
    if debug:
        print 'doManQQ', input_fname, chrom_col, offset_col, pval_cols, title, grey, ctitle, outdir
    rcmd = '%s%s' % (
        rcode, rcode2 %
        (input_fname, chrom_col, offset_col, pval_cols, title, grey))
    if debug:
        print 'running\n%s\n' % rcmd
    rlog, flist = RRun(rcmd=rcmd, title=ctitle, outdir=outdir)
    rlog.append('## R script=')
    rlog.append(rcmd)
    return rlog, flist
Esempio n. 2
0
def doManQQ(input_fname,chrom_col,offset_col,pval_cols,title,grey,ctitle,outdir,beTidy=False):
    """ 
    we may have an interval file or a tabular file - if interval, will have chr1... so need to adjust
    to chrom numbers
    draw a qq for pvals and a manhattan plot if chrom/offset <> 0
    contains some R scripts as text strings - we substitute defaults into the calls
    to make them do our bidding - and save the resulting code for posterity
    this can be called externally, I guess...for QC eg?
    """
    if debug:
	print 'doManQQ',input_fname,chrom_col,offset_col,pval_cols,title,grey,ctitle,outdir
    ffd,filtered_fname = tempfile.mkstemp(prefix='rgManQQtemp')
    f = open(filtered_fname,'w')
    inf = open(input_fname,'r')
    ohead = inf.readline().strip().split('\t') # see if we have a header
    inf.seek(0) # rewind
    newhead = ['pval%d' % (x+1) for x in pval_cols]
    newhead.insert(0,'Offset')
    newhead.insert(0,'Chrom')
    havehead = 0
    wewant = [chrom_col,offset_col]
    wewant += pval_cols
    try:
        allnums = ['%d' % x for x in ohead] # this should barf if non numerics == header row?
        f.write('\t'.join(newhead)) # for R to read
        f.write('\n')
    except:
        havehead = 1
        newhead = [ohead[chrom_col],ohead[offset_col]]
        newhead += [ohead[x] for x in pval_cols]
        f.write('\t'.join(newhead)) # use the original head
        f.write('\n')
    for i,row in enumerate(inf):
        if i == 0 and havehead:
            continue # ignore header
        sr = row.strip().split('\t')
        if len(sr) > 1:
            if sr[chrom_col].lower().find('chr') <> -1:
                sr[chrom_col] = sr[chrom_col][3:]
            newr = [sr[x] for x in wewant] # grab cols we need
            s = '\t'.join(newr)
            f.write(s)
            f.write('\n')
    f.close()
    pvc = [x+3 for x in range(len(pval_cols))] # 2 for offset and chrom, 1 for r offset start
    pvc = 'c(%s)' % (','.join(map(str,pvc)))
    rcmd = '%s%s' % (rcode,rcode2 % (filtered_fname,'1','2',pvc,title,grey))
    if debug:
	print 'running\n%s\n' % rcmd
    rlog,flist = RRun(rcmd=rcmd,title=ctitle,outdir=outdir)
    rlog.append('## R script=')
    rlog.append(rcmd)
    if beTidy:
        os.unlink(filtered_fname)
    return rlog,flist
Esempio n. 3
0
def doManQQ(input_fname,chrom_col,offset_col,pval_cols,title,grey,ctitle,outdir,beTidy=False):
    """ 
    we may have an interval file or a tabular file - if interval, will have chr1... so need to adjust
    to chrom numbers
    draw a qq for pvals and a manhattan plot if chrom/offset <> 0
    contains some R scripts as text strings - we substitute defaults into the calls
    to make them do our bidding - and save the resulting code for posterity
    this can be called externally, I guess...for QC eg?
    """
    ffd,filtered_fname = tempfile.mkstemp(prefix='rgManQQtemp')
    f = open(filtered_fname,'w')
    inf = open(input_fname,'r')
    ohead = inf.readline().strip().split('\t') # see if we have a header
    inf.seek(0) # rewind
    newhead = ['pval%d' % (x+1) for x in pval_cols]
    newhead.insert(0,'Offset')
    newhead.insert(0,'Chrom')
    havehead = 0
    wewant = [chrom_col,offset_col]
    wewant += pval_cols
    try:
        allnums = ['%d' % x for x in ohead] # this should barf if non numerics == header row?
        f.write('\t'.join(newhead)) # for R to read
        f.write('\n')
    except:
        havehead = 1
        newhead = [ohead[chrom_col],ohead[offset_col]]
        newhead += [ohead[x] for x in pval_cols]
        f.write('\t'.join(newhead)) # use the original head
        f.write('\n')
    for i,row in enumerate(inf):
        if i == 0 and havehead:
            continue # ignore header
        sr = row.strip().split('\t')
        if len(sr) > 1:
            if sr[chrom_col].lower().find('chr') <> -1:
                sr[chrom_col] = sr[chrom_col][3:]
            newr = [sr[x] for x in wewant] # grab cols we need
            s = '\t'.join(newr)
            f.write(s)
            f.write('\n')
    f.close()
    pvc = [x+3 for x in range(len(pval_cols))] # 2 for offset and chrom, 1 for r offset start
    pvc = 'c(%s)' % (','.join(map(str,pvc)))
    rcmd = '%s%s' % (rcode,rcode2 % (filtered_fname,'1','2',pvc,title,grey))
    rlog,flist = RRun(rcmd=rcmd,title=ctitle,outdir=outdir)
    rlog.append('## R script=')
    rlog.append(rcmd)
    if beTidy:
        os.unlink(filtered_fname)
    return rlog,flist
Esempio n. 4
0
def doManQQ(input_fname,chrom_col,offset_col,pval_cols,title,grey,ctitle,outdir,beTidy=False):
    """ 
    we may have an interval file or a tabular file - if interval, will have chr1... so need to adjust
    to chrom numbers
    draw a qq for pvals and a manhattan plot if chrom/offset <> 0
    contains some R scripts as text strings - we substitute defaults into the calls
    to make them do our bidding - and save the resulting code for posterity
    this can be called externally, I guess...for QC eg?
    """
    if debug:
        print 'doManQQ',input_fname,chrom_col,offset_col,pval_cols,title,grey,ctitle,outdir
    rcmd = '%s%s' % (rcode,rcode2 % (input_fname,chrom_col,offset_col,pval_cols,title,grey))
    if debug:
        print 'running\n%s\n' % rcmd
    rlog,flist = RRun(rcmd=rcmd,title=ctitle,outdir=outdir)
    rlog.append('## R script=')
    rlog.append(rcmd)
    return rlog,flist