|
0
|
1 # -*- coding: utf-8 -*-
|
|
|
2 """
|
|
|
3 Created on Fri Feb 26 18:49:15 2016
|
|
|
4
|
|
|
5 @author: chmaramis
|
|
|
6 """
|
|
|
7
|
|
|
8 from __future__ import division
|
|
|
9 import numpy as np
|
|
|
10 from pandas import *
|
|
|
11 from numpy import nan as NA
|
|
|
12 import sys
|
|
|
13 import time
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17 def publicVGeneClonoFunc(inputs,thres):
|
|
|
18
|
|
|
19 clono=DataFrame()
|
|
|
20
|
|
|
21 for x in range(0,len(inputs),2):
|
|
|
22 cl = DataFrame()
|
|
|
23 cl = read_csv(inputs[x] , sep = '\t' , index_col = 0)
|
|
|
24 #tp = read_csv(inp_name, iterator=True, chunksize=5000,sep='\t', index_col=0 )
|
|
|
25 #cl = concat([chunk for chunk in tp])
|
|
|
26
|
|
|
27 if (thres != 'null'):
|
|
|
28 cl = cl[cl['Reads'] > int(thres)]
|
|
|
29
|
|
|
30 x1 = inputs[x+1].split('_')
|
|
|
31
|
|
|
32 del cl['Reads']
|
|
|
33 cl.columns = [cl.columns[0], cl.columns[1], x1[0]+' '+cl.columns[2], x1[0]+' Relative '+cl.columns[3]]
|
|
|
34
|
|
|
35 if clono.empty:
|
|
|
36 clono = cl
|
|
|
37 else:
|
|
|
38 clono = clono.merge(cl, how='outer', on=['V-GENE','AA JUNCTION'])
|
|
|
39
|
|
|
40
|
|
|
41 col = clono.columns
|
|
|
42 freqs = col.map(lambda x: 'Frequency' in x)
|
|
|
43 reads = col.map(lambda x: 'Reads/Total' in x)
|
|
|
44
|
|
|
45 clono[col[freqs]] = clono[col[freqs]].fillna(0)
|
|
|
46 clono[col[reads]] = clono[col[reads]].fillna('0/*')
|
|
|
47
|
|
|
48 clono['Num of Patients']= clono[col[freqs]].apply(lambda x: np.sum(x != 0), axis=1)
|
|
|
49
|
|
|
50 clono = clono[clono['Num of Patients'] > 1]
|
|
|
51
|
|
|
52 clono.index = range(1,len(clono)+1)
|
|
|
53
|
|
|
54 return clono
|
|
|
55
|
|
|
56
|
|
|
57 if __name__ == '__main__':
|
|
|
58
|
|
|
59 start=time.time()
|
|
|
60
|
|
|
61 # Parse input arguments
|
|
|
62 arg = sys.argv[3:]
|
|
|
63 output = sys.argv[1]
|
|
|
64 thres = sys.argv[2]
|
|
|
65
|
|
|
66
|
|
|
67 # Execute basic function
|
|
|
68 mer = publicVGeneClonoFunc(arg,thres)
|
|
|
69
|
|
|
70 # Save output to CSV files
|
|
|
71 if not mer.empty:
|
|
|
72 mer.to_csv(output , sep = '\t')
|
|
|
73
|
|
|
74 # Print execution time
|
|
|
75 stop=time.time()
|
|
|
76 print('Runtime:' + str(stop-start))
|