code: def csv_writer(parser, keep, extract, args):
      
      # The output
      output = sys.stdout if args.output == "-" else open(args.output, "w")
  
      try:
          # Getting the samples
          samples = np.array(parser.get_samples(), dtype=str)
          k = _get_sample_select(samples=samples, keep=keep)
  
          # Writing the CSV header
          print("sample_id", "variant_id", "chromosome", "position", "reference",
                "coded", "dosage", "hard_call", sep=",", file=output)
  
          # The data generator
          generator = _get_generator(parser=parser, extract=extract, keep=k,
                                     check_maf=args.maf)
  
          # The number of markers extracted
          nb_extracted = 0
  
          for data in generator:
              # Keeping only the required genotypes
              genotypes = data.genotypes
  
              # The hard call mapping
              hard_call_mapping = {
                  0: "{ref}/{ref}".format(ref=data.reference),
                  1: "{ref}/{alt}".format(ref=data.reference, alt=data.coded),
                  2: "{alt}/{alt}".format(alt=data.coded),
              }
  
              for sample, geno in zip(samples[k], genotypes):
                  # Is the genotype missing
                  is_missing = np.isnan(geno)
  
                  # Hard coding (NaN values are empty string)
                  hard_coded = None
                  if is_missing:
                      geno = ""
                      hard_coded = ""
                  else:
                      hard_coded = hard_call_mapping[int(round(geno, 0))]
  
                  print(sample, data.variant.name, data.variant.chrom,
                        data.variant.pos, data.reference, data.coded,
                        geno, hard_coded, sep=",", file=output)
  
              nb_extracted += 1
  
          if nb_extracted == 0:
              logger.warning("No markers matched the extract list")
  
      finally:
          output.close()
docs: Writes the data in CSV format.