Skip to content

Commit

Permalink
improved
Browse files Browse the repository at this point in the history
  • Loading branch information
tdiprima committed Jan 3, 2020
1 parent 84d726b commit eb36c2b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions file_gen_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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']
Expand Down Expand Up @@ -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']:
Expand All @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit eb36c2b

Please sign in to comment.