comparison venn_diagram.py @ 8:bca31ac678f1 draft

planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
author proteore
date Fri, 28 Jun 2019 05:18:44 -0400
parents d1fd04dcb13a
children e744a43171ff
comparison
equal deleted inserted replaced
7:98b7912a9ceb 8:bca31ac678f1
45 title_dict[title] = name 45 title_dict[title] = name
46 ids = set() 46 ids = set()
47 if input_type == "file": 47 if input_type == "file":
48 header = inputs[i][3] 48 header = inputs[i][3]
49 ncol = inputs[i][4] 49 ncol = inputs[i][4]
50 file_content = open(input_file, "r").readlines() 50 with open(input_file,"r") as handle :
51 file_content = csv.reader(handle,delimiter="\t")
52 file_content = list(file_content) #csv object to list
51 53
52 # Check if column number is in right form 54 # Check if column number is in right form
53 if isnumber("int", ncol.replace("c", "")): 55 if isnumber("int", ncol.replace("c", "")):
54 if header == "true": 56 if header == "true":
55 file_content = [x.strip() for x in [line.split("\t")[int(ncol.replace("c", ""))-1].split(";")[0] for line in file_content[1:]]] # take only first IDs 57 file_content = [x for x in [line[int(ncol.replace("c", ""))-1].split(";") for line in file_content[1:]]] # gets ids from defined column
58 else:
59 file_content = [x for x in [line[int(ncol.replace("c", ""))-1].split(";") for line in file_content]]
56 else: 60 else:
57 file_content = [x.strip() for x in [line.split("\t")[int(ncol.replace("c", ""))-1].split(";")[0] for line in file_content]] # take only first IDs 61 raise ValueError("Please fill in the right format of column number")
58 else:
59 raise ValueError("Please fill in the right format of column number")
60 else: 62 else:
61 ids = set() 63 ids = set()
62 file_content = inputs[i][0].split() 64 file_content = inputs[i][0].split()
65 file_content = [x.split(";") for x in file_content]
63 66
67 file_content = [item.strip() for sublist in file_content for item in sublist if item != ''] #flat list of list of lists, remove empty items
64 ids.update(file_content) 68 ids.update(file_content)
65 if 'NA' in ids : ids.remove('NA') 69 if 'NA' in ids : ids.remove('NA')
66 comp_dict[title] = ids 70 comp_dict[title] = ids
67 71
68 return comp_dict, title_dict 72 return comp_dict, title_dict