def write_pair_fastq(fastq_file1, fastq_file2, orig_read1, orig_read2,
                     new_pairs):

    n_pair = len(new_pairs)
    i = 1
    for pair in new_pairs:
        # give each fastq record a new name giving:
        # 1 - the original name of the read
        # 2 - the coordinates the two ends of the pair should map to
        # 3 - the number of the read
        # 4 - the total number of reads being remapped

        pos_str = "%d-%d" % (min(orig_read1.pos + 1, orig_read2.pos + 1),
                             max(orig_read1.pos + 1, orig_read2.pos + 1))

        name = "%s.%s.%d.%d" % (orig_read1.qname, pos_str, i, n_pair)

        fastq_file1.write("@%s\n%s\n+%s\n%s\n" %
                          (name, pair[0], name, orig_read1.qual))

        rev_seq = util.revcomp(pair[1])
        fastq_file2.write("@%s\n%s\n+%s\n%s\n" %
                          (name, rev_seq, name, orig_read2.qual))

        i += 1
def write_pair_fastq(fastq_file1, fastq_file2, orig_read1, orig_read2,
                     new_pairs):

    n_pair = len(new_pairs)
    i = 1
    for pair in new_pairs:
        # give each fastq record a new name giving:
        # 1 - the original name of the read
        # 2 - the coordinates the two ends of the pair should map to
        # 3 - the number of the read
        # 4 - the total number of reads being remapped

        pos_str = "%d-%d" % (min(orig_read1.pos+1, orig_read2.pos+1),
                             max(orig_read1.pos+1, orig_read2.pos+1))
        
        name = "%s.%s.%d.%d" % (orig_read1.qname, pos_str, i, n_pair)
        
        fastq_file1.write("@%s\n%s\n+%s\n%s\n" %
                          (name, pair[0], name, orig_read1.qual))

        rev_seq = util.revcomp(pair[1])
        fastq_file2.write("@%s\n%s\n+%s\n%s\n" %
                          (name, rev_seq, name, orig_read2.qual))

        i += 1
Exemple #3
0
def write_pair_fastq(fastq_file1, fastq_file2, orig_read1, orig_read2,
                     new_pairs, files):

    # create new names for new reads keeping track of chromosome and matched position of original read
    # give each fastq record a new name giving:
    # 1 - the original name of the read
    # 2 - the chrom the reads should map
    # 3 - the coordinates the two ends of the pair should map to

    pos_str = "%d-%d" % (min(orig_read1.pos + 1, orig_read2.pos + 1),
                         max(orig_read1.pos + 1, orig_read2.pos + 1))

    name = "%s.%s.%s" % (orig_read1.qname, orig_read1.reference_name, pos_str)

    ## save original and new reads
    ## check which read neads to be reversed
    if orig_read1.is_reverse:
        rev = util.revcomp(orig_read1.seq)
        rev_q = orig_read1.qual[::-1]
        fastq_file1.write("@%s\n%s\n+%s\n%s\n" %
                          (orig_read1.qname, rev, orig_read1.qname, rev_q))
        fastq_file2.write("@%s\n%s\n+%s\n%s\n" %
                          (orig_read2.qname, orig_read2.seq, orig_read2.qname,
                           orig_read2.qual))

        rev_seq = util.revcomp(new_pairs[0])
        fastq_file1.write("@%s\n%s\n+%s\n%s\n" % (name, rev_seq, name, rev_q))

        fastq_file2.write("@%s\n%s\n+%s\n%s\n" %
                          (name, new_pairs[1], name, orig_read2.qual))

    else:
        rev = util.revcomp(orig_read2.seq)
        rev_q = orig_read2.qual[::-1]

        fastq_file1.write("@%s\n%s\n+%s\n%s\n" %
                          (orig_read1.qname, orig_read1.seq, orig_read1.qname,
                           orig_read1.qual))
        fastq_file2.write("@%s\n%s\n+%s\n%s\n" %
                          (orig_read2.qname, rev, orig_read2.qname, rev_q))
        rev_seq = util.revcomp(new_pairs[1])
        fastq_file1.write("@%s\n%s\n+%s\n%s\n" %
                          (name, new_pairs[0], name, orig_read1.qual))

        fastq_file2.write("@%s\n%s\n+%s\n%s\n" % (name, rev_seq, name, rev_q))