forked from Rahi13/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idmapper_without_pandas.py
43 lines (30 loc) · 1.25 KB
/
idmapper_without_pandas.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# The script takes two csv files and maps the said column together based on the anhor(common)colum.
# The script only workks when there is one-to-one mapping between the anchor column and said column in files
#anchor_file1 and anchor_file2 needs to be the common column. same format.
import csv
infile1='/Users/rsn13/Desktop/scripts/input/glycan_chebi.csv'
infile2='/Users/rsn13/Desktop/scripts/input/glycan_xref_reactome.csv'
outfile = '/Users/rsn13/Desktop/scripts/output/mapped.txt'
dct1 ={}
dct2 = {}
anchor_file1 = 0
anchor_file2 = 0
column_file1 = 1
column_file2 = 1
with open(infile1) as csv_file1:
csv_reader1 = csv.reader(csv_file1, delimiter=',')
for line in csv_reader1:
dct1[line[anchor_file1]] = line[column_file1]
with open(infile2) as csv_file2:
csv_reader2 = csv.reader(csv_file2, delimiter=',')
for line in csv_reader2:
dct2[line[anchor_file2]] = line[column_file2]
for anchor1,id1 in dct1.items():
sourceFile = open(outfile,'a')
for anchor2,id2 in dct2.items():
if anchor1 == anchor2:
print(anchor1,anchor2,id1,id2,file=sourceFile)
sourceFile.close()
csv_file1.close()
csv_file2.close()
print('Done')