Combine metadata
0
0
Entering edit mode
21 months 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])
python metadata genome • 905 views
ADD COMMENT
0
Entering edit mode

Have you tried adding debugging statements to check if each line is reached? What have you tried on your own?

ADD REPLY
0
Entering edit mode

Yes, I tried debugging, please see below code. It seems working good but not printing any things after if condition.

for row in clean:
    line = row.strip().split(',')
    biosamp = line[0]
    location = line[1]
    host = line[2]
    date = line[4]
    #print(line)
    for row2 in run:
        #print(row2)
        line2 = row2.split(',')
        #print(line2)
        if line2[25] == biosamp:
            sra = line2[0]
            print(sra)
            url = line2[9]
            print(url)
writer.writerow([biosamp, sra, location, host, date, url])
ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

It is printing "print(line2)" if I give the print function before if condition. I am not aware about invisible characters.

ADD REPLY
0
Entering edit mode

Wait, does it literally print print(line2)? Or does it print the content of the line2 variable?

ADD REPLY
0
Entering edit mode

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.

for row2 in run:
        line2 = row2.split(',')
        print(line2)
        if line2[25] == biosamp:
            sra = line2[0]
            url = line2[9]
            print(url)
ADD REPLY
0
Entering edit mode

Please be more clear when you answer follow-up questions on the forum. Did you try printing invisible characters?

ADD REPLY
0
Entering edit mode

Why did you delete the post, Kumar?

ADD REPLY

Login before adding your answer.

Traffic: 2926 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6