I would like do perform division with respect to its alphabet. Given an example as below:
The binary file given is in csv format:
A=1000, C=0100, G=0010, T=0001
binary.csv: CAT, GAA
0,1,0,0,1,0,0,0,0,0,0,1
0,0,1,0,1,0,0,0,1,0,0,0
The binary.csv need to multiply with a single line values which is in csv file.
single.csv:
0.28,0.22,0.23,0.27,0.12,0.29,0.34,0.21,0.44,0.56,0.51,0.65
The code below do multiplication for values in both files and output:
0.22,0.12,0.65
0.23,0.12,0.44
Code
import csv
with open('single.csv', 'rb') as csvfile:
for row in csv.reader(csvfile, delimiter=','):
reals = row
with open('binary.csv', 'rb') as csvfile:
pwreader = csv.reader(csvfile, delimiter=',')
with open('output.csv','wb') as testfile:
csv_writer=csv.writer(testfile)
for row in pwreader:
result = []
for i,b in enumerate(row):
if b == '1' :
result.append(reals[i])
csv_writer.writerow(result)
I have additional csv file that I would like to perform division for previous output and the values that are divided with respect to its alphabet:
A C G T
0.4,0.5,0.7,0.1
0.2,0.8,0.9,0.3
the value for CAT is divided by 0.5,0.4,0.1 and GAA is divided by 0.9,0.2,0.2 respectively so that I can get a whole new output as follows:
0.44,0.3,6.5
0.26,0.6,2.2
using numpy on array can possibly solve this but when used on more than couple of thousands data it might not be suitable. Out of memory was occurred when I tried on 60,000++ data.
Can anyone help me?