0
|
1 # -*- coding: utf-8 -*-
|
|
2 """
|
|
3 Created on Sat Mar 24 17:45:09 2018
|
|
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 sw_clonos = lambda x: x.startswith('Clonotypes')
|
|
16 sw_freq = lambda x: x.startswith('Freq')
|
|
17 sw_gene = lambda x: x.endswith('GENE')
|
|
18
|
|
19 def geneComparison(inputs):
|
|
20
|
|
21 mer=DataFrame()
|
|
22
|
|
23 for x in range(0,len(inputs),2):
|
|
24
|
|
25 ini = read_csv(inputs[x] , sep = '\t' , index_col = 0)
|
|
26
|
|
27 ini.drop(ini.columns[np.where(ini.columns.map(sw_clonos))[0]], axis=1, inplace=True)
|
|
28
|
|
29 x1 = inputs[x+1].split('_')
|
|
30 ini.rename(columns={ini.columns[np.where(ini.columns.map(sw_freq))[0][0]]: x1[0]}, inplace=True)
|
|
31
|
|
32 if mer.empty:
|
|
33 mer = DataFrame(ini)
|
|
34 else:
|
|
35 mer = merge(mer,ini, on=ini.columns[np.where(ini.columns.map(sw_gene))[0][0]] , how='outer')
|
|
36
|
|
37 mer=mer.fillna(0)
|
|
38 mer['mean'] = mer.sum(axis=1)/(len(mer.columns)-1)
|
|
39 fr = 'mean'
|
|
40
|
|
41 mer=mer.sort_values(by = fr,ascending=False)
|
|
42 mer[fr] = mer[fr].map('{:.4f}'.format)
|
|
43 mer.index = range(1,len(mer)+1)
|
|
44
|
|
45 return mer
|
|
46
|
|
47
|
|
48 if __name__ == '__main__':
|
|
49
|
|
50 start=time.time()
|
|
51
|
|
52 # Parse input arguments
|
|
53 inputs = sys.argv[2:]
|
|
54 output = sys.argv[1]
|
|
55
|
|
56 # Execute basic function
|
|
57 mer = geneComparison(inputs)
|
|
58
|
|
59 # Save output to CSV files
|
|
60 if not mer.empty:
|
|
61 mer.to_csv(output , sep = '\t')
|
|
62
|
|
63 # Print execution time
|
|
64 stop=time.time()
|
|
65 print('Runtime:' + str(stop-start))
|