diff exclusive_clonotype_computation.py @ 0:0e37e5b73273 draft

Initial commit
author chmaramis
date Fri, 30 Mar 2018 07:22:29 -0400
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/exclusive_clonotype_computation.py	Fri Mar 30 07:22:29 2018 -0400
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Sat Mar 24 17:31:38 2018
+
+@author: chmaramis
+"""
+
+from __future__ import division
+import numpy as np
+from pandas import *
+from numpy import nan as NA
+import sys
+import time
+
+clono_def = {'CDR3': ['AA JUNCTION'],
+             'VCDR3': ['V-GENE','AA JUNCTION'],
+             'JCDR3': ['J-GENE','AA JUNCTION']}
+
+
+def exclusiveClonotypeComputation(inputs, clono, thres):
+    
+    clono_comps = clono_def[clono]
+
+    vClono=DataFrame()
+    
+    # File A
+    cl = DataFrame()
+    cl = read_csv(inputs[0] , sep = '\t' , index_col = 0)
+    if (thres != 'null'):
+                cl = cl[cl['Reads'] > int(thres)]
+    vClono = cl
+    
+    # File B
+    cl = DataFrame()
+    cl = read_csv(inputs[2] , sep = '\t' , index_col = 0)
+    if (thres != 'null'):
+                cl = cl[cl['Reads'] > int(thres)]
+    cl.rename(columns={'Reads':'ReadsB'}, inplace=True)
+    vClono = vClono.merge(cl[clono_comps+['ReadsB']], how='left', on=clono_comps)
+    
+    vClono['ReadsB'].fillna(0, inplace=True)
+        
+    vClono = vClono[vClono['ReadsB'] == 0]
+    del vClono['ReadsB']
+    
+    vClono.index = range(1,len(vClono)+1)
+    
+    return vClono    
+
+
+if __name__ == '__main__':   
+
+    start=time.time()    
+    
+    # Parse input arguments
+    arg = sys.argv[4:]
+    clono = sys.argv[1]
+    output = sys.argv[2]
+    threshold = sys.argv[3]
+        
+    # Execute basic function
+    excl = exclusiveClonotypeComputation(arg, clono, threshold)
+    
+    # Save output to CSV files
+    if not excl.empty:
+        excl.to_csv(output , sep = '\t') 
+
+    # Print execution time
+    stop=time.time()
+    print('Runtime:' + str(stop-start))