-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnormalize-counts.py
More file actions
executable file
·51 lines (46 loc) · 1.88 KB
/
Copy pathnormalize-counts.py
File metadata and controls
executable file
·51 lines (46 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
#=========================================================================
# This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
# License (GPL) version 3, as described at www.opensource.org.
# Copyright (C)2021 William H. Majoros <bmajoros@alumni.duke.edu>
#=========================================================================
from __future__ import (absolute_import, division, print_function,
unicode_literals, generators, nested_scopes, with_statement)
from builtins import (bytes, dict, int, list, object, range, str, ascii,
chr, hex, input, next, oct, open, pow, round, super, filter, map, zip)
# The above imports should allow this program to run in both Python 2 and
# Python 3. You might need to update your version of module "future".
import sys
import os
import ProgramName
import gzip
from Rex import Rex
rex=Rex()
BIG_NUMBER=1e7
#=========================================================================
# main()
#=========================================================================
if(len(sys.argv)!=3):
exit(ProgramName.get()+" <infile> <outdir>\n")
(infile,outdir)=sys.argv[1:]
outfile=outdir+"/"+infile
OUT=gzip.open(outfile,"wt")
IN=gzip.open(infile,"rt")
header=IN.readline()
print(header,end="",file=OUT)
rex.findOrDie("DNA=(\\d+)\\s+RNA=(\\d+)",header)
numDNA=int(rex[1]); numRNA=int(rex[2])
for line in IN:
fields=line.rstrip().split()
fields=[int(x) for x in fields]
DNAcounts=fields[:numDNA]
RNAcounts=fields[numDNA:(numDNA+numRNA)]
DNAlibs=fields[(numDNA+numRNA):(2*numDNA+numRNA)]
RNAlibs=fields[(2*numDNA+numRNA):]
for i in range(numDNA):
DNAcounts[i]=DNAcounts[i]/DNAlibs[i]*BIG_NUMBER
for i in range(numRNA):
RNAcounts[i]=RNAcounts[i]/RNAlibs[i]*BIG_NUMBER
fields=DNAcounts; fields.extend(RNAcounts)
print("\t".join([str(x) for x in fields]),file=OUT)
IN.close(); OUT.close()