Mercurial > repos > davidvanzessen > argalaxy_tools
comparison experimental_design/experimental_design.py @ 12:010402c959aa draft
Uploaded
| author | davidvanzessen |
|---|---|
| date | Tue, 04 Aug 2015 10:00:20 -0400 |
| parents | f90fbc15b35a |
| children | 672d5e010b1f |
comparison
equal
deleted
inserted
replaced
| 11:0510cf1f7cbc | 12:010402c959aa |
|---|---|
| 1 import sys | |
| 2 import pandas as pd | |
| 3 | |
| 4 def main(): | |
| 5 patients = {} | |
| 6 files = [] | |
| 7 sample_id = sys.argv[1] | |
| 8 imgt_files = 0 | |
| 9 blast_files = 0 | |
| 10 #organize files | |
| 11 for arg in sys.argv[2:-2]: | |
| 12 if arg.find("/") is -1: | |
| 13 patients[sample_id] = files | |
| 14 files = [] | |
| 15 sample_id = arg | |
| 16 else: | |
| 17 df = pd.read_csv(arg, sep="\t", dtype=object, error_bad_lines=False) | |
| 18 if "Functionality" in list(df.columns.values): | |
| 19 df["VDJ Frame"][df["Functionality"] != "productive"] = "In-frame with stop codon" | |
| 20 imgt_files += 1 | |
| 21 else: | |
| 22 blast_files += 1 | |
| 23 files.append(df) | |
| 24 patients[sample_id] = files | |
| 25 columns = [u'ID', u'VDJ Frame', u'Top V Gene', u'Top D Gene', u'Top J Gene', u'CDR1 Seq', u'CDR1 Length', u'CDR2 Seq', u'CDR2 Length', u'CDR3 Seq', u'CDR3 Length', u'CDR3 Seq DNA', u'CDR3 Length DNA', u'Strand', u'CDR3 Found How', u'Functionality', 'V-REGION identity %', 'V-REGION identity nt', 'D-REGION reading frame', 'AA JUNCTION', 'Functionality comment', 'Sequence', 'FR1-IMGT', 'FR2-IMGT', 'FR3-IMGT', 'CDR3-IMGT', 'JUNCTION', 'J-REGION', 'FR4-IMGT', 'P3V-nt nb', 'N1-REGION-nt nb', 'P5D-nt nb', 'P3D-nt nb', 'N2-REGION-nt nb', 'P5J-nt nb', '3V-REGION trimmed-nt nb', '5D-REGION trimmed-nt nb', '3D-REGION trimmed-nt nb', '5J-REGION trimmed-nt nb', u'Sample', u'Replicate'] | |
| 26 if blast_files is not 0: | |
| 27 print "Has a parsed blastn file, using limited columns." | |
| 28 columns = [u'ID', u'VDJ Frame', u'Top V Gene', u'Top D Gene', u'Top J Gene', u'CDR1 Seq', u'CDR1 Length', u'CDR2 Seq', u'CDR2 Length', u'CDR3 Seq', u'CDR3 Length', u'CDR3 Seq DNA', u'CDR3 Length DNA', u'Strand', u'CDR3 Found How', u'Sample', u'Replicate'] | |
| 29 | |
| 30 result = None | |
| 31 for patient_id, samples in patients.iteritems(): | |
| 32 count = 1 | |
| 33 for sample in samples: | |
| 34 sample['Sample'] = patient_id | |
| 35 sample['Replicate'] = str(count) | |
| 36 count += 1 | |
| 37 if result is None: | |
| 38 result = sample[columns] | |
| 39 else: | |
| 40 result = result.append(sample[columns]) | |
| 41 result.to_csv(sys.argv[-1], sep="\t", index=False, index_label="index") | |
| 42 | |
| 43 if __name__ == "__main__": | |
| 44 main() |
