Mercurial > repos > md-anderson-bioinformatics > matrix_manipulation
comparison Test_input_into_file.py @ 1:f1bcd79cd923 draft default tip
Uploaded
author | insilico-bob |
---|---|
date | Tue, 27 Nov 2018 14:20:40 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:7f12c81e2083 | 1:f1bcd79cd923 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 #Created on Jule 23, 2018 | |
4 | |
5 # @author: Bob Brown | |
6 | |
7 import sys | |
8 import os | |
9 | |
10 def main(): | |
11 | |
12 # Grab the inputs from the Galaxy xml interface and write to a file that is passed to the program | |
13 # Not each of the parameters as separate command line variables. | |
14 # ab_gene_name_for_header={} | |
15 # ab_rrid_for_header={} | |
16 dir= "/Users/bobbrown/Desktop/junk/" | |
17 accepted_extensions = ["csv", "tsv"] | |
18 filenames = [fn for fn in os.listdir(dir) if fn.split(".")[-1] in accepted_extensions] | |
19 for f in filenames: | |
20 print("filename= "+f) | |
21 os.remove(dir+f) | |
22 | |
23 sys.exit(0) | |
24 | |
25 ab_gene_name_for_header={'abc':'geneName'} | |
26 ab_rrid_for_header={'abc':'rrid123'} | |
27 line= 'abc,123\n' | |
28 | |
29 pos= line.find(",") | |
30 ABname= line[0:pos] | |
31 ABnewName= ABname+ "|"+ab_gene_name_for_header[ABname]+"|"+ab_rrid_for_header[ABname] | |
32 line= ABnewName+line[pos:] | |
33 line= line.replace(',','\t') | |
34 sys.exit(0) | |
35 # try: | |
36 print(' \n starting Test program read params from file stored in tools dir. Arguments=') | |
37 print(str(sys.argv[1:])+'\n') | |
38 | |
39 if False: | |
40 infileName = sys.argv[1] | |
41 # directory = sys.argv[2] | |
42 directory = '/Users/bobbrown/Desktop/' | |
43 outfileName = sys.argv[3] #use later | |
44 # outfile = sys.argv[6] | |
45 | |
46 #sys.stdout.write | |
47 | |
48 # ifile= open(directory+"/"+infileName,'rU') | |
49 ifile= open(directory+infileName,'rU') | |
50 ofile= open(directory+outfileName,'w') | |
51 # ofile= open('/Users/bobbrown/Desktop/TestOutFileVarParams.txt','w') | |
52 | |
53 cnt= 0 | |
54 # for param in range(2,len(sys.argv)): | |
55 # cnt +=1 | |
56 # ofile.write("param "+str(cnt)+"= "+param+"\n") | |
57 | |
58 | |
59 for param in ifile: | |
60 cnt +=1 | |
61 ofile.write("param "+str(cnt)+"= "+param) | |
62 | |
63 ifile.close() | |
64 | |
65 ofile.close() | |
66 | |
67 print('Fini -- rows read = '+str(cnt)+'\n') | |
68 | |
69 # except : | |
70 # print('Error>>> ') | |
71 | |
72 return | |
73 ## | |
74 ## | |
75 | |
76 if __name__ == '__main__': main() | |
77 #sys.exit(0) |