Entering edit mode
2.4 years ago
Kumar
▴
170
I am trying to combine two metadata files using the following script. However, it generate output file (meta.tsv) with header but not generating any records. Any suggestion will be appreciated.
with open('SraInfo.csv') as run, open ('biosample_meta.tsv') as clean,
open('meta.tsv', 'w') as final:
writer = csv.writer(final, dialect=csv.excel_tab)
writer.writerow(['Biosample', 'ID', 'Loc', 'Host', 'date', 'URL'])
for row in clean:
line = row.strip().split('\t')
biosamp = line[0]
location = line[1]
host = line[2]
date = line[3]
for row2 in run:
line2 = row2.split('\t')
if line2[25] == biosamp:
url = line2[9]
writer.writerow([biosam, location, host, date, url])
Have you tried adding debugging statements to check if each line is reached? What have you tried on your own?
Yes, I tried debugging, please see below code. It seems working good but not printing any things after if condition.
There could be invisible characters affecting the match condition. I don't know much python, but see if you can print
line2
with invisible characters.It is printing "print(line2)" if I give the print function before if condition. I am not aware about invisible characters.
Wait, does it literally print
print(line2)
? Or does it print the content of theline2
variable?It is printing the content of the line2. I am doing the following. I think, the problem is in the if condition but I am not catching that. It is not print any after if condition.
Please be more clear when you answer follow-up questions on the forum. Did you try printing invisible characters?
Why did you delete the post, Kumar?