code: def sam_to_fastq(sam):
      '''Given a pysam alignment, returns the sequence a Fastq object.
         Reverse complements as required and add suffix /1 or /2 as appropriate from the flag'''
      name = sam.qname
      if sam.is_read1:
          name += '/1'
      elif sam.is_read2:
          name += '/2'
      else:
          raise Error('Read ' + name + ' must be first or second of pair according to flag. Cannot continue')
  
      seq = pyfastaq.sequences.Fastq(name, common.decode(sam.seq), common.decode(sam.qual))
      if sam.is_reverse:
          seq.revcomp()
  
      return sef sam_to_fastq(sam):
      '''Given a pysam alignment, returns the sequence a Fastq object.
         Reverse complements as required and add suffix /1 or /2 as appropriate from the flag'''
      name = sam.qname
      if sam.is_read1:
          name += '/1'
      elif sam.is_read2:
          name += '/2'
      else:
          raise Error('Read ' + name + ' must be first or second of pair according to flag. Cannot continue')
  
      seq = pyfastaq.sequences.Fastq(name, common.decode(sam.seq), common.decode(sam.qual))
      if sam.is_reverse:
          seq.revcomp()
  
      return seq
docs: Given a pysam alignment, returns the sequence a Fastq object.
         Reverse complements as required and add suffix /1 or /2 as appropriate from the flag