annotate galaxy_micropita/src/breadcrumbs/scripts/scriptEnvToTable.py @ 3:8fb4630ab314 draft default tip

Uploaded
author sagun98
date Thu, 03 Jun 2021 17:07:36 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
1 #!/usr/bin/env python
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
2 """
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
3 Author: Timothy Tickle
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
4 Description: Convert Env file to table
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
5 """
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
6
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
7 __author__ = "Timothy Tickle"
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
8 __copyright__ = "Copyright 2012"
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
9 __credits__ = ["Timothy Tickle"]
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
10 __license__ = ""
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
11 __version__ = ""
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
12 __maintainer__ = "Timothy Tickle"
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
13 __email__ = "ttickle@sph.harvard.edu"
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
14 __status__ = "Development"
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
15
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
16 import sys
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
17 import argparse
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
18 import csv
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
19
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
20
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
21 #Set up arguments reader
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
22 argp = argparse.ArgumentParser( prog = "scriptEnvToTable.py",
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
23 description = """Convert Env file to table""" )
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
24
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
25 #Arguments
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
26 #For table
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
27 argp.add_argument("strEnvFile", metavar = "EnvFile", help ="EnvFile data file")
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
28 argp.add_argument("strOutputFile", metavar = "OutputFile", help ="Output File")
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
29 args = argp.parse_args( )
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
30
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
31 hndlReader = csv.reader(open(args.strEnvFile,'rU'), delimiter="\t")
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
32
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
33 lsListOfIDs = []
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
34 lsListOfFeatures = []
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
35 dictValues = {}
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
36 for lsLine in hndlReader:
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
37 print(lsLine)
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
38 lsListOfIDs.append(lsLine[1])
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
39 lsListOfFeatures.append(lsLine[0])
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
40 tpleKey = tuple([lsLine[1],lsLine[0]])
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
41 if tpleKey in dictValues:
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
42 print("Error:: Duplicate key entries found")
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
43 exit(1)
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
44 dictValues[tpleKey] = lsLine[2]
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
45
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
46 lsListOfIDs = list(set(lsListOfIDs))
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
47 lsListOfFeatures = list(set(lsListOfFeatures))
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
48 print(lsListOfIDs)
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
49 print(lsListOfFeatures)
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
50 hndlWrite = csv.writer(open(args.strOutputFile,'w'), delimiter="\t")
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
51 hndlWrite.writerow(["ID"]+lsListOfIDs)
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
52 for sFeature in lsListOfFeatures:
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
53 lsFeatureLine = [sFeature]
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
54 for sSample in lsListOfIDs:
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
55 lsFeatureLine.append(dictValues.get(tuple([sSample,sFeature]),0))
8fb4630ab314 Uploaded
sagun98
parents:
diff changeset
56 hndlWrite.writerow(lsFeatureLine)