def usageTab(types, sample, avrstats, stdstats, type2genelist, outdir): for type in types: avrgene2count = {} stdgene2count = {} totalreads = 0 totaluniqs = 0 if type in avrstats: avrgene2count = avrstats[type] stdgene2count = stdstats[type] totalreads = sum([counts[0] for counts in avrgene2count.values()]) totaluniqs = sum([counts[1] for counts in avrgene2count.values()]) #if totalreads == 0 or totaluniqs == 0: # raise ValueError("sample with zero read/sequence") if type in type2genelist: genes = type2genelist[type] else: genes = sorted( avrgene2count.keys() ) typedir = os.path.join(outdir, type) outfile = os.path.join(typedir, "%s-%s.txt" %(sample, type) ) f = open(outfile, 'w') f.write("Gene\tReads\t%Reads\tUniq\t%uniq\tStdReads\tStdUniq\n") #numpass = 0 for g in genes: if g not in avrgene2count: sys.stderr.write("Gene %s is not in avrgene2count %s\n" %(g, ','.join(avrgene2count.keys()) )) avrcounts = [0.0, 0.0] stdcounts = [0.0, 0.0] else: #numpass += 1 avrcounts = avrgene2count[g] stdcounts = stdgene2count[g] read = avrcounts[0] uniq = avrcounts[1] readPc = 0.0 uniqPc = 0.0 if totalreads > 0: readPc = iseqlib.getPc(read, totalreads) if totaluniqs > 0: uniqPc = iseqlib.getPc(uniq, totaluniqs) f.write("%s\t%d\t%f\t%d\t%f\t%d\t%d\n" %(g, read, readPc, uniq, uniqPc, stdcounts[0], stdcounts[1])) f.close()
def tab(f, colnames, sample2row): #Print total: totalRow = sample2row['Total'] f.write("%s & %s \\\\\n" % ("Total", " & ".join( ["%s & 100.00" %cell for cell in totalRow] )) ) f.write("\\hline\n") for sample in sorted(sample2row.keys()): if sample == 'Total' or sample == 'controls' or sample == 'patients' : continue f.write("%s" % iseqlib.properName(sample)) row = sample2row[sample] for i, cell in enumerate(row): total = totalRow[i] pc = iseqlib.getPc( int(cell), int(total) ) f.write( " & %s & %.2f " %(cell, pc) ) f.write("\\\\\n") f.write("\\hline\n")