nodes: 0, module; 1, function_definition; 2, function_name:read_magic_file; 3, parameters; 4, block; 5, identifier:self; 6, identifier:path; 7, identifier:sort_by_this_name; 8, expression_statement; 9, expression_statement; 10, try_statement; 11, comment:# fin=open(path,'r'); 12, comment:# fin.readline(); 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, for_statement; 17, comment:# fin.close(); 18, expression_statement; 19, return_statement; 20, comment:"""
          reads a magic formated data file from path and sorts the keys
          according to sort_by_this_name
  
          Parameters
          ----------
          path : path to file to read
          sort_by_this_name : variable to sort data by
          """; 21, assignment; 22, block; 23, except_clause; 24, assignment; 25, assignment; 26, assignment; 27, identifier:line; 28, subscript; 29, block; 30, call; 31, parenthesized_expression; 32, identifier:DATA; 33, dictionary; 34, with_statement; 35, identifier:FileNotFoundError; 36, block; 37, identifier:line; 38, subscript; 39, identifier:header; 40, call; 41, identifier:error_strings; 42, list; 43, identifier:lines; 44, slice; 45, expression_statement; 46, expression_statement; 47, for_statement; 48, if_statement; 49, expression_statement; 50, attribute; 51, argument_list; 52, identifier:DATA; 53, with_clause; 54, block; 55, return_statement; 56, identifier:lines; 57, integer:0; 58, attribute; 59, argument_list; 60, integer:1; 61, assignment; 62, assignment; 63, identifier:i; 64, call; 65, block; 66, comparison_operator:tmp_data[sort_by_this_name] in list(DATA.keys()); 67, block; 68, assignment; 69, identifier:finput; 70, identifier:close; 71, with_item; 72, expression_statement; 73, list; 74, call; 75, identifier:split; 76, string; 77, identifier:tmp_data; 78, dictionary; 79, identifier:tmp_line; 80, call; 81, identifier:range; 82, argument_list; 83, expression_statement; 84, subscript; 85, call; 86, expression_statement; 87, comment:# only print each error message once; 88, if_statement; 89, subscript; 90, identifier:tmp_data; 91, as_pattern; 92, assignment; 93, attribute; 94, argument_list; 95, string_content; 96, attribute; 97, argument_list; 98, call; 99, assignment; 100, identifier:tmp_data; 101, identifier:sort_by_this_name; 102, identifier:list; 103, argument_list; 104, assignment; 105, comparison_operator:error_string not in error_strings; 106, block; 107, identifier:DATA; 108, subscript; 109, call; 110, as_pattern_target; 111, identifier:lines; 112, call; 113, identifier:line; 114, identifier:strip; 115, string; 116, escape_sequence:\t; 117, call; 118, identifier:split; 119, string; 120, identifier:len; 121, argument_list; 122, subscript; 123, subscript; 124, call; 125, identifier:error_string; 126, binary_operator:"-E- ERROR: magic file %s has more than one line for %s %s" % (
                      path, sort_by_this_name, tmp_data[sort_by_this_name]); 127, identifier:error_string; 128, identifier:error_strings; 129, expression_statement; 130, expression_statement; 131, identifier:tmp_data; 132, identifier:sort_by_this_name; 133, identifier:open; 134, argument_list; 135, identifier:finput; 136, identifier:list; 137, argument_list; 138, string_content; 139, attribute; 140, argument_list; 141, string_content; 142, identifier:tmp_line; 143, identifier:tmp_data; 144, subscript; 145, identifier:tmp_line; 146, identifier:i; 147, attribute; 148, argument_list; 149, string:"-E- ERROR: magic file %s has more than one line for %s %s"; 150, tuple; 151, call; 152, call; 153, identifier:path; 154, string; 155, subscript; 156, escape_sequence:\n; 157, identifier:line; 158, identifier:strip; 159, string; 160, escape_sequence:\t; 161, identifier:header; 162, identifier:i; 163, identifier:DATA; 164, identifier:keys; 165, identifier:path; 166, identifier:sort_by_this_name; 167, subscript; 168, identifier:print; 169, argument_list; 170, attribute; 171, argument_list; 172, string_content:r; 173, call; 174, slice; 175, string_content; 176, identifier:tmp_data; 177, identifier:sort_by_this_name; 178, identifier:error_string; 179, identifier:error_strings; 180, identifier:append; 181, identifier:error_string; 182, attribute; 183, argument_list; 184, integer:1; 185, escape_sequence:\n; 186, identifier:finput; 187, identifier:readlines
code: def read_magic_file(self, path, sort_by_this_name):
          """
          reads a magic formated data file from path and sorts the keys
          according to sort_by_this_name
  
          Parameters
          ----------
          path : path to file to read
          sort_by_this_name : variable to sort data by
          """
          DATA = {}
          try:
              with open(path, 'r') as finput:
                  lines = list(finput.readlines()[1:])
          except FileNotFoundError:
              return []
          # fin=open(path,'r')
          # fin.readline()
          line = lines[0]
          header = line.strip('\n').split('\t')
          error_strings = []
          for line in lines[1:]:
              tmp_data = {}
              tmp_line = line.strip('\n').split('\t')
              for i in range(len(tmp_line)):
                  tmp_data[header[i]] = tmp_line[i]
              if tmp_data[sort_by_this_name] in list(DATA.keys()):
                  error_string = "-E- ERROR: magic file %s has more than one line for %s %s" % (
                      path, sort_by_this_name, tmp_data[sort_by_this_name])
                  # only print each error message once
                  if error_string not in error_strings:
                      print(error_string)
                      error_strings.append(error_string)
              DATA[tmp_data[sort_by_this_name]] = tmp_data
          # fin.close()
          finput.close()
          return(DATA)