nodes: 0, module; 1, function_definition; 2, function_name:hydra_to_vcf_writer; 3, parameters; 4, block; 5, identifier:hydra_file; 6, identifier:genome_2bit; 7, identifier:options; 8, identifier:out_handle; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, for_statement; 14, comment:"""Write hydra output as sorted VCF file.
  
      Requires loading the hydra file into memory to perform sorting
      on output VCF. Could generalize this to no sorting or by-chromosome
      approach if this proves too memory intensive.
      """; 15, call; 16, assignment; 17, call; 18, identifier:brend; 19, identifier:brends; 20, block; 21, identifier:_write_vcf_header; 22, argument_list; 23, identifier:brends; 24, call; 25, attribute; 26, argument_list; 27, expression_statement; 28, identifier:out_handle; 29, identifier:list; 30, argument_list; 31, identifier:brends; 32, identifier:sort; 33, keyword_argument; 34, call; 35, call; 36, identifier:key; 37, call; 38, identifier:_write_vcf_breakend; 39, argument_list; 40, identifier:_get_vcf_breakends; 41, argument_list; 42, identifier:attrgetter; 43, argument_list; 44, identifier:brend; 45, identifier:out_handle; 46, identifier:hydra_file; 47, identifier:genome_2bit; 48, identifier:options; 49, string:"chrom"; 50, string:"pos"
code: def hydra_to_vcf_writer(hydra_file, genome_2bit, options, out_handle):
      """Write hydra output as sorted VCF file.
  
      Requires loading the hydra file into memory to perform sorting
      on output VCF. Could generalize this to no sorting or by-chromosome
      approach if this proves too memory intensive.
      """
      _write_vcf_header(out_handle)
      brends = list(_get_vcf_breakends(hydra_file, genome_2bit, options))
      brends.sort(key=attrgetter("chrom", "pos"))
      for brend in brends:
          _write_vcf_breakend(brend, out_handle)