def extract_reads_from_interleaved(input_fp, forward_id, reverse_id, output_dir):
 forward_fp = join(output_dir, 'forward_reads.fastq')
 reverse_fp = join(output_dir, 'reverse_reads.fastq')
 ffp = open(forward_fp, 'w')
 rfp = open(reverse_fp, 'w')
 for (label, seq, qual) in parse_fastq(qiime_open(input_fp), strict=False, enforce_qual_range=False):
  fastq_string = format_fastq_record(label, seq, qual)
  if (forward_id in label):
   ffp.write(fastq_string)
  elif ((reverse_id in label) and (forward_id not in label)):
   rfp.write(fastq_string)
  else:
   ffp.close()
   rfp.close()
   raise ValueError(("One of the input sequences doesn't have either identifier or it has both.\nLabel: %s\nForward: %s\n Reverse: %s" % (label, forward_id, reverse_id)))
 ffp.close()
 rfp.close()

def extract_reads_from_interleaved ( input_fp , forward_id , reverse_id , output_dir ) : forward_fp = join ( output_dir , 'forward_reads.fastq' ) reverse_fp = join ( output_dir , 'reverse_reads.fastq' ) ffp = open ( forward_fp , 'w' ) rfp = open ( reverse_fp , 'w' ) for ( label , seq , qual ) in parse_fastq ( qiime_open ( input_fp ) , strict = False , enforce_qual_range = False ) : fastq_string = format_fastq_record ( label , seq , qual ) if ( forward_id in label ) : ffp . write ( fastq_string ) elif ( ( reverse_id in label ) and ( forward_id not in label ) ) : rfp . write ( fastq_string ) else : ffp . close ( ) rfp . close ( ) raise ValueError ( ( "One of the input sequences doesn't have either identifier or it has both.\nLabel: %s\nForward: %s\n Reverse: %s" % ( label , forward_id , reverse_id ) ) ) ffp . close ( ) rfp . close ( )
parses a single fastq file and creates two new files: forward and reverse .