comparison src/breadcrumbs/scripts/scriptEnvToTable.py @ 0:0de566f21448 draft default tip

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