-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_script.py
More file actions
28 lines (28 loc) · 1.19 KB
/
Copy pathpython_script.py
File metadata and controls
28 lines (28 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
import psycopg2
with open("/Users/emilyso/Documents/ThirdYear/BCB330/microbial_metafunctional_maps/EmilySo/Emily_Stable.txt","r") as file_2, \
open("/Users/emilyso/Documents/ThirdYear/BCB330/microbial_metafunctional_maps/EmilySo/new_input_data.txt","w") as out:
# connection = psycopg2.connect(user = "meta_user",
# password = "",
# host = "localhost",
# port = "5432",
# database = "string_sample_tables")
# curs = connection.cursor()
# curs.execute("CREATE TABLE new_input_data(refseq varchar,ncbi_taxid varchar,locus varchar,name varchar,strain varchar,genus varchar,supergroup varchar)")
next(file_2)
for line in file_2:
line_split = line.split('\t')
description = line_split[1].split('|')
if len(description) >= 9:
locus = description[8]
name = description[6]
else:
locus = "N/A"
name = description[4]
strain = line_split[4]
genus = line_split[5]
supergroup = line_split[9]
refseq = description[3]
ncbi_taxid = line_split[3]
out.write(refseq+'\t'+ncbi_taxid+'\t'+locus+'\t'+name+'\t'+strain+'\t'+genus+'\t'+supergroup+'\n')
out.flush()