|
0
|
1 # -*- coding: utf-8 -*-
|
|
|
2 """
|
|
|
3 Created on Mon Feb 29 11:12:09 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 exclusiveCDR3Func(inputs,thres):
|
|
|
18
|
|
|
19 cdr3=DataFrame()
|
|
|
20
|
|
|
21 # File A
|
|
|
22 cl = DataFrame()
|
|
|
23 cl = read_csv(inputs[0] , sep = '\t' , index_col = 0)
|
|
|
24 if (thres != 'null'):
|
|
|
25 cl = cl[cl['Reads'] > int(thres)]
|
|
|
26 cdr3 = cl
|
|
|
27
|
|
|
28 # File B
|
|
|
29 cl = DataFrame()
|
|
|
30 cl = read_csv(inputs[2] , sep = '\t' , index_col = 0)
|
|
|
31 if (thres != 'null'):
|
|
|
32 cl = cl[cl['Reads'] > int(thres)]
|
|
|
33 cl.rename(columns={'Reads':'ReadsB'}, inplace=True)
|
|
|
34 cdr3 = cdr3.merge(cl[['AA JUNCTION','ReadsB']], how='left', on='AA JUNCTION')
|
|
|
35
|
|
|
36 cdr3['ReadsB'].fillna(0, inplace=True)
|
|
|
37
|
|
|
38 cdr3 = cdr3[cdr3['ReadsB'] == 0]
|
|
|
39 del cdr3['ReadsB']
|
|
|
40
|
|
|
41 cdr3.index = range(1,len(cdr3)+1)
|
|
|
42
|
|
|
43 return cdr3
|
|
|
44
|
|
|
45
|
|
|
46 if __name__ == '__main__':
|
|
|
47
|
|
|
48 start=time.time()
|
|
|
49
|
|
|
50 # Parse input arguments
|
|
|
51 threshold = sys.argv[2]
|
|
|
52 arg = sys.argv[3:]
|
|
|
53 output = sys.argv[1]
|
|
|
54
|
|
|
55 # Execute basic function
|
|
|
56 excl = exclusiveCDR3Func(arg,threshold)
|
|
|
57
|
|
|
58 # Save output to CSV files
|
|
|
59 if not excl.empty:
|
|
|
60 excl.to_csv(output , sep = '\t')
|
|
|
61
|
|
|
62 # Print execution time
|
|
|
63 stop=time.time()
|
|
|
64 print('Runtime:' + str(stop-start))
|