Mercurial > repos > chmaramis > testirprofiler
diff cmpb2016/compare_repertoire_V.py @ 0:8be019b173e6 draft
Uploaded included tools
| author | chmaramis |
|---|---|
| date | Sun, 18 Mar 2018 05:54:20 -0400 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cmpb2016/compare_repertoire_V.py Sun Mar 18 05:54:20 2018 -0400 @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Sep 16 12:50:43 2014 + +@author: chmaramis +""" + +from __future__ import division +import numpy as np +from pandas import * +from numpy import nan as NA +import sys +import time + +sw_reads = lambda x: x.startswith('Reads') +sw_freq = lambda x: x.startswith('Freq') +sw_gene = lambda x: x.startswith('V') + +def freqtoall(inputs): + + mer=DataFrame() + + for x in range(0,len(inputs),2): + + ini = read_csv(inputs[x] , sep = '\t' , index_col = 0) + + ini.drop(ini.columns[np.where(ini.columns.map(sw_reads))[0]], axis=1, inplace=True) + + x1 = inputs[x+1].split('_') + ini.rename(columns={ini.columns[np.where(ini.columns.map(sw_freq))[0][0]]: x1[0]}, inplace=True) + + if mer.empty: + mer = DataFrame(ini) + else: + mer = merge(mer,ini, on=ini.columns[np.where(ini.columns.map(sw_gene))[0][0]] , how='outer') + + mer=mer.fillna(0) + mer['mean'] = mer.sum(axis=1)/(len(mer.columns)-1) + fr = 'mean' + + mer=mer.sort_values(by = fr,ascending=False) + mer[fr] = mer[fr].map('{:.4f}'.format) + mer.index = range(1,len(mer)+1) + + return mer + + +if __name__ == '__main__': + + start=time.time() + + # Parse input arguments + inputs = sys.argv[2:] + output = sys.argv[1] + + # Execute basic function + mer = freqtoall(inputs) + + # Save output to CSV files + if not mer.empty: + mer.to_csv(output , sep = '\t') + + # Print execution time + stop=time.time() + print('Runtime:' + str(stop-start))
