nodes: 0, module; 1, function_definition; 2, function_name:get_sorted_series_files; 3, parameters; 4, block; 5, identifier:self; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, expression_statement; 13, expression_statement; 14, comment:# select sublist with SeriesNumber; 15, if_statement; 16, expression_statement; 17, expression_statement; 18, if_statement; 19, expression_statement; 20, for_statement; 21, expression_statement; 22, if_statement; 23, if_statement; 24, if_statement; 25, return_statement; 26, identifier:startpath; 27, string:""; 28, identifier:series_number; 29, None; 30, identifier:return_files_with_info; 31, False; 32, identifier:sort_keys; 33, string:"SliceLocation"; 34, identifier:return_files; 35, True; 36, identifier:remove_doubled_slice_locations; 37, True; 38, comment:"""
          Function returns sorted list of dicom files. File paths are organized
          by SeriesUID, StudyUID and FrameUID
  
  
          :param startpath: path prefix. E.g. "~/data"
          :param series_number: ID of series used for filtering the data
          :param return_files_with_info: return more complex information about sorted files
          :param return_files: return simple list of sorted files
          :type sort_keys: One key or list of keys used for sorting method by the order of keys.
  
          """; 39, assignment; 40, comparison_operator:series_number is not None; 41, block; 42, assignment; 43, call; 44, identifier:remove_doubled_slice_locations; 45, block; 46, assignment; 47, identifier:onefile; 48, identifier:dcmdir; 49, block; 50, assignment; 51, identifier:return_files; 52, block; 53, identifier:return_files_with_info; 54, block; 55, comparison_operator:len(retval) == 0; 56, block; 57, elif_clause; 58, else_clause; 59, identifier:retval; 60, identifier:dcmdir; 61, subscript; 62, identifier:series_number; 63, None; 64, expression_statement; 65, identifier:dcmdir; 66, call; 67, attribute; 68, argument_list; 69, expression_statement; 70, identifier:filelist; 71, list; 72, expression_statement; 73, comment:# head, tail = os.path.split(onefile['filename']); 74, identifier:retval; 75, list; 76, expression_statement; 77, expression_statement; 78, call; 79, integer:0; 80, expression_statement; 81, comparison_operator:len(retval) == 1; 82, block; 83, block; 84, attribute; 85, slice; 86, assignment; 87, identifier:sort_list_of_dicts; 88, argument_list; 89, identifier:logger; 90, identifier:debug; 91, binary_operator:'SeriesNumber: ' + str(series_number); 92, assignment; 93, call; 94, call; 95, call; 96, identifier:len; 97, argument_list; 98, assignment; 99, call; 100, integer:1; 101, expression_statement; 102, expression_statement; 103, identifier:self; 104, identifier:files_with_info; 105, identifier:dcmdir; 106, list_comprehension; 107, identifier:dcmdir; 108, keyword_argument; 109, string; 110, call; 111, identifier:dcmdir; 112, call; 113, attribute; 114, argument_list; 115, attribute; 116, argument_list; 117, attribute; 118, argument_list; 119, identifier:retval; 120, identifier:retval; 121, None; 122, identifier:len; 123, argument_list; 124, assignment; 125, assignment; 126, identifier:line; 127, for_in_clause; 128, if_clause; 129, identifier:keys; 130, identifier:sort_keys; 131, string_content:SeriesNumber:; 132, identifier:str; 133, argument_list; 134, attribute; 135, argument_list; 136, identifier:filelist; 137, identifier:append; 138, call; 139, identifier:retval; 140, identifier:append; 141, identifier:filelist; 142, identifier:retval; 143, identifier:append; 144, identifier:dcmdir; 145, identifier:retval; 146, identifier:retval; 147, subscript; 148, identifier:retval; 149, call; 150, identifier:line; 151, identifier:dcmdir; 152, comparison_operator:line['SeriesNumber'] == series_number; 153, identifier:series_number; 154, identifier:self; 155, identifier:_remove_doubled_slice_locations; 156, identifier:dcmdir; 157, attribute; 158, argument_list; 159, identifier:retval; 160, integer:0; 161, identifier:tuple; 162, argument_list; 163, subscript; 164, identifier:series_number; 165, attribute; 166, identifier:join; 167, identifier:startpath; 168, attribute; 169, subscript; 170, identifier:retval; 171, identifier:line; 172, string; 173, identifier:os; 174, identifier:path; 175, identifier:self; 176, identifier:dirpath; 177, identifier:onefile; 178, string; 179, string_content:SeriesNumber; 180, string_content:filename
code: def get_sorted_series_files(self, startpath="", series_number=None, return_files_with_info=False,
                                  sort_keys="SliceLocation", return_files=True, remove_doubled_slice_locations=True):
          """
          Function returns sorted list of dicom files. File paths are organized
          by SeriesUID, StudyUID and FrameUID
  
  
          :param startpath: path prefix. E.g. "~/data"
          :param series_number: ID of series used for filtering the data
          :param return_files_with_info: return more complex information about sorted files
          :param return_files: return simple list of sorted files
          :type sort_keys: One key or list of keys used for sorting method by the order of keys.
  
          """
          dcmdir = self.files_with_info[:]
  
          # select sublist with SeriesNumber
          if series_number is not None:
              dcmdir = [
                  line for line in dcmdir if line['SeriesNumber'] == series_number
              ]
          dcmdir = sort_list_of_dicts(dcmdir, keys=sort_keys)
  
          logger.debug('SeriesNumber: ' + str(series_number))
  
          if remove_doubled_slice_locations:
              dcmdir = self._remove_doubled_slice_locations(dcmdir)
  
          filelist = []
          for onefile in dcmdir:
              filelist.append(os.path.join(startpath,
                                           self.dirpath, onefile['filename']))
              # head, tail = os.path.split(onefile['filename'])
  
  
          retval = []
          if return_files:
              retval.append(filelist)
          if return_files_with_info:
              retval.append(dcmdir)
  
          if len(retval) == 0:
              retval = None
          elif len(retval) == 1:
              retval = retval[0]
          else:
              retval = tuple(retval)
  
          return retval