annotate experimental_design/experimental_design.py @ 6:d001d0c05dbe draft

Uploaded
author davidvanzessen
date Fri, 16 Dec 2016 07:30:32 -0500
parents afe85eb6572e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
1 import sys
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
2 import pandas as pd
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
3
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
4 def main():
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
5 patients = {}
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
6 files = []
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
7 sample_id = sys.argv[1]
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
8 imgt_files = 0
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
9 blast_files = 0
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
10 #organize files
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
11 for arg in sys.argv[2:-2]:
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
12 if arg.find("/") is -1:
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
13 patients[sample_id] = files
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
14 files = []
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
15 sample_id = arg
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
16 else:
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
17 df = pd.read_csv(arg, sep="\t", dtype=object, error_bad_lines=False)
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
18 if "Functionality" in list(df.columns.values):
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
19 df["VDJ Frame"][df["Functionality"] != "productive"] = "In-frame with stop codon"
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
20 imgt_files += 1
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
21 else:
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
22 blast_files += 1
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
23 files.append(df)
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
24 patients[sample_id] = files
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
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',
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
26 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 %',
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
27 'V-REGION identity nt', 'D-REGION reading frame', 'AA JUNCTION', 'Functionality comment', 'Sequence', 'FR1-IMGT', 'FR2-IMGT',
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
28 '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',
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
29 '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']
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
30 if "N-REGION-nt nb" in files[0].columns:
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
31 columns.insert(30, "N-REGION-nt nb")
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
32 if blast_files is not 0:
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
33 print "Has a parsed blastn file, using limited columns."
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
34 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']
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
35
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
36 result = None
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
37 for patient_id, samples in patients.iteritems():
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
38 count = 1
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
39 for sample in samples:
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
40 sample['Sample'] = patient_id
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
41 sample['Replicate'] = str(count)
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
42 count += 1
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
43 if result is None:
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
44 result = sample[columns]
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
45 else:
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
46 result = result.append(sample[columns])
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
47 result.to_csv(sys.argv[-1], sep="\t", index=False, index_label="index")
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
48
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
49 if __name__ == "__main__":
afe85eb6572e Uploaded
davidvanzessen
parents:
diff changeset
50 main()