-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_info-advanced
42 lines (41 loc) · 1.66 KB
/
get_info-advanced
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
#SEARCH A TABLE AND PULL SELECTED INFORMATION FROM IT
#You must provide: a reference table (tsv or xls file) with each sample as a row and each characteristic (age, gender, collection date, etc.) as a column;
#the ID you will be using to look up samples must be the first column. It doesn't matter if there are column headers or not.
#You need to know the number of each column you want to output (i.e. first column is 1).
#You must also provide: an input list with the sample IDs you want to look up (csv, tsv, xls, or txt file), with the IDs each on a separate line.
reference=input("What is the reference table?")
ref_open=open(reference, "r")
input_entry=input("What is the input list?")
input_open=open(input_entry, "r")
output_list=[]
a=0
while a == 0:
output=input("Which column do you want to print? Input one at a time.")
output_list.append(int(output)-1)
done=input("Are you done selecting columns? Type y or n")
if done is "y":
a+=1
input_read=input_open.read().splitlines()
keys=[]
keys2=[]
values=[]
values2=[]
for record in ref_open:
end=record.find("\t")
end1=end+1
keys.append(record[0:end1])
values.append(record[0:])
for eachkey in keys:
keys2.append(eachkey.replace("\n", "").replace("\t", ""))
for eachvalue in values:
values2.append(eachvalue.replace("\n", ""))
dict_IDs=dict(zip(keys2, values2))
for line in input_read:
if line not in dict_IDs.keys():
print("N/A")
if line in dict_IDs.keys():
line2=dict_IDs[line].split("\t")
accessed_mapping = map(line2.__getitem__, output_list)
accessed_list = list(accessed_mapping)
line3='\t'.join(map(str, accessed_list))
print(line3)