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