Dear group, I am trying to automate a process in statistical language R.
There for 1 operation 50 lines of code is written. This process query postgres database and does some processing on the resulting data and writes back a file. I want to replicate the 50 line code, 90 times, by substituting with postgres.table_id and file name at 2 places. File_A: 1 \t molA 2 \t molB 3 \t molC ........ 90 \t molABC File_B: (R-code) (50 lines) library(Rdbi) library(RdbiPgSQL) library(Biobase) library(multtest) conn <- dbConnect(PgSQL(),dbname = 'mol-test') mq = "SELECT DISTINCT target.target_name, go_term from target, comb, moltab,gos,sequence,go_seq where target.target_id = comb.target_id AND comb.mol_id = $MOL_ID AND target.target_name = sequence.seq_name AND sequence.seq_id = go_seq.seq_id AND go_seq.gos_id = gos.gos_id AND gos.go_cat = 'F';" ........... ........... write.table(mol_towrite,"$MOL_NAME_adj_pval",sep='t',quote=F,col.names=F) ### Here there are two varialbes, $MOL_ID and $MOL_NAME in select statement and write.table statement respectively. I want to read File_A, loop through it and substitute $MOL_ID = 1 and $MOL_NAME = A I want to reproduce 50 lines * 90 times substituting ID and NAME by looping through File_A. I tried using re module, I do not know if this correct or wrong. for m in file_A: cols = m.split('\t') molid = cols[0].strip() molname = cols[1].strip() for k in file_B: pat1 = '$MOL_ID' pat2 = '$MOL_NAME' if re.search(pat1,k): s = Template(k) s.substitute($MOL_ID,molid) if re.search(pat2,k): t = Template(k) t.substitute($MOL_NAME,molname) However, this is not working, somehow. Can any one help me please. If more simple methods are available please show a new way. Thanks Sri __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor