From eb36c2bfb10dcf9770002a2a07f235d15af490a8 Mon Sep 17 00:00:00 2001 From: Tammy DiPrima Date: Fri, 3 Jan 2020 12:33:34 -0500 Subject: [PATCH] improved --- file_gen_util.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/file_gen_util.py b/file_gen_util.py index 39242e7..a055f6d 100644 --- a/file_gen_util.py +++ b/file_gen_util.py @@ -12,17 +12,18 @@ def check_if_duplicates(list_of_elems): if len(dupe) > 0: print('THE FOLLOWING FILES ARE ATTACHED TO MORE THAN ONE IMAGE!!') for d in dupe: - print(' * ' + str(d)) # stringify just in case + print(str(d)) # stringify just in case def check_if_not_found(list_of_elems): if len(list_of_elems) > 0: print('DID NOT FIND!!') for i in list_of_elems: - print(' * ' + str(i)) # ditto. + print(str(i)) # stringify. + print('DID NOT FIND.') -def find_row(replace_str, search, image_list, manifest_type, f): +def find_row(replace_str, search, image_list, manifest_type, f, collection=""): found1 = 0 search_term = "" if replace_str: @@ -45,19 +46,20 @@ def find_row(replace_str, search, image_list, manifest_type, f): found1 = 1 # Write to file if manifest_type == 'map': - f.write(row[1] + "," + row[2] + "," + row[3] + "," + search.strip() + "\n") + f.write(collection + "," + row[1] + "," + row[2] + "," + row[3] + "," + search.strip() + "\n") to_be_uploaded.append(search_term.strip()) else: if manifest_type == 'segmentation': f.write(search_term.strip() + "," + row[1] + "," + row[2] + "," + row[3].strip()) to_be_uploaded.append(row[3].strip()) break - return found1, key1 + return found1, search.rstrip() def main(my_args): image_list = my_args['download'] manifest_type = my_args['type'] + collection_name = my_args['collection'] replace_str = '' if my_args['string']: replace_str = my_args['string'] @@ -86,7 +88,7 @@ def main(my_args): f.write('segmentdir,studyid,clinicaltrialsubjectid,imageid\n') if manifest_type == 'map': - f.write('studyid,clinicaltrialsubjectid,imageid,filename\n') + f.write('collectionname,studyid,clinicaltrialsubjectid,imageid,filename\n') not_found = [] if my_args['file']: @@ -96,7 +98,7 @@ def main(my_args): key = search_term # skip blank lines if len(search_term.strip()) > 0: - found, key = find_row(replace_str, search_term, image_list, manifest_type, f) + found, key = find_row(replace_str, search_term, image_list, manifest_type, f, collection_name) if not found: not_found.append(key) else: @@ -125,10 +127,17 @@ def main(my_args): group.add_argument("-f", "--file", help="Path to input file", type=str) group.add_argument("-d", "--directory", help="Path to input directory", type=str) parser.add_argument("-dl", "--download", help="Path to downloaded quip file", required=True, type=str) + parser.add_argument("-c", "--collection", help="Collection name", required=False, type=str) parser.add_argument("-t", "--type", help="Type of manifest", required=True, type=str) parser.add_argument("-s", "--string", help="Substring to replace", required=False, type=str) + args = vars(parser.parse_args()) + if not args['collection'] and ("map" in args['type'].lower()): + parser.error("\n--type map requires --collection") + # 1) Download httplinks.csv from PathDB # 2) ls -l | awk '{print $9}' > ~/myList.list main(args) + print('Done.') + exit(0)