code: def load_maf(
          path,
          optional_cols=[],
          sort_key=variant_ascending_position_sort_key,
          distinct=True,
          raise_on_error=True,
          encoding=None):
      maf_df = load_maf_dataframe(path, raise_on_error=raise_on_error, encoding=encoding)
      if len(maf_df) == 0 and raise_on_error:
          raise ValueError("Empty MAF file %s" % path)
      ensembl_objects = {}
      variants = []
      metadata = {}
      for _, x in maf_df.iterrows():
          contig = x.Chromosome
          if isnull(contig):
              error_message = "Invalid contig name: %s" % (contig,)
              if raise_on_error:
                  raise ValueError(error_message)
              else:
                  logging.warn(error_message)
                  continue
          start_pos = x.Start_Position
          ref = x.Reference_Allele
          ncbi_build = x.NCBI_Build
          if ncbi_build in ensembl_objects:
              ensembl = ensembl_objects[ncbi_build]
          else:
              if isinstance(ncbi_build, int):
                  reference_name = "B%d" % ncbi_build
              else:
                  reference_name = str(ncbi_build)
              ensembl = infer_genome(reference_name)
              ensembl_objects[ncbi_build] = ensembl
          if x.Tumor_Seq_Allele1 != ref:
              alt = x.Tumor_Seq_Allele1
          else:
              if x.Tumor_Seq_Allele2 == ref:
                  error_message = (
                      "Both tumor alleles agree with reference %s: %s" % (
                          ref, x,))
                  if raise_on_error:
                      raise ValueError(error_message)
                  else:
                      logging.warn(error_message)
                      continue
              alt = x.Tumor_Seq_Allele2
          variant = Variant(
              contig,
              start_pos,
              str(ref),
              str(alt),
              ensembl=ensembl)
          metadata[variant] = {
              'Hugo_Symbol': x.Hugo_Symbol,
              'Center': x.Center,
              'Strand': x.Strand,
              'Variant_Classification': x.Variant_Classification,
              'Variant_Type': x.Variant_Type,
              'dbSNP_RS': x.dbSNP_RS,
              'dbSNP_Val_Status': x.dbSNP_Val_Status,
              'Tumor_Sample_Barcode': x.Tumor_Sample_Barcode,
              'Matched_Norm_Sample_Barcode': x.Matched_Norm_Sample_Barcode,
          }
          for optional_col in optional_cols:
              if optional_col in x:
                  metadata[variant][optional_col] = x[optional_col]
          variants.append(variant)
      return VariantCollection(
          variants=variants,
          source_to_metadata_dict={path: metadata},
          sort_key=sort_key,
          distinct=distinct)