def main():
    input_filename = sys.argv[1]
    input_type = sys.argv[2] or 'sanger'
    mate1_filename = sys.argv[3]
    mate2_filename = sys.argv[4]
    single1_filename = sys.argv[5]
    single2_filename = sys.argv[6]

    type = input_type
    input = fastqNamedReader(open(input_filename, 'rb'), format=type)
    mate1_out = fastqWriter(open(mate1_filename, 'wb'), format=type)
    mate2_out = fastqWriter(open(mate2_filename, 'wb'), format=type)
    single1_out = fastqWriter(open(single1_filename, 'wb'), format=type)
    single2_out = fastqWriter(open(single2_filename, 'wb'), format=type)
    joiner = fastqJoiner(type)

    i = None
    skip_count = 0
    found = {}
    for i, read in enumerate(
            fastqReader(open(input_filename, 'rb'), format=type)):

        if read.identifier in found:
            del found[read.identifier]
            continue

        mate1 = input.get(read.identifier)

        mate2 = input.get(joiner.get_paired_identifier(mate1))

        if mate2:
            # This is a mate pair
            found[mate2.identifier] = None
            if joiner.is_first_mate(mate1):
                mate1_out.write(mate1)
                mate2_out.write(mate2)
            else:
                mate1_out.write(mate2)
                mate2_out.write(mate1)
        else:
            # This is a single
            skip_count += 1
            if joiner.is_first_mate(mate1):
                single1_out.write(mate1)
            else:
                single2_out.write(mate1)

    if i is None:
        print "Your input file contained no valid FASTQ sequences."
    else:
        if skip_count:
            print 'There were %i reads with no mate.' % skip_count
        print 'De-interlaced %s pairs of sequences.' % (
            (i - skip_count + 1) / 2)

    input.close()
    mate1_out.close()
    mate2_out.close()
    single1_out.close()
    single2_out.close()
Exemple #2
0
def main():
    #Read command line arguments
    input1_filename = sys.argv[1]
    input1_type = sys.argv[2] or 'sanger'
    input2_filename = sys.argv[3]
    input2_type = sys.argv[4] or 'sanger'
    output_filename = sys.argv[5]

    if input1_type != input2_type:
        print "WARNING: You are trying to join files of two different types: %s and %s." % (
            input1_type, input2_type)

    input2 = fastqNamedReader(open(input2_filename, 'rb'), input2_type)
    joiner = fastqJoiner(input1_type)
    out = fastqWriter(open(output_filename, 'wb'), format=input1_type)

    i = None
    skip_count = 0
    for i, fastq_read in enumerate(
            fastqReader(open(input1_filename, 'rb'), format=input1_type)):
        identifier = joiner.get_paired_identifier(fastq_read)
        fastq_paired = input2.get(identifier)
        if fastq_paired is None:
            skip_count += 1
        else:
            out.write(joiner.join(fastq_read, fastq_paired))
    out.close()

    if i is None:
        print "Your file contains no valid FASTQ reads."
    else:
        print input2.has_data()
        print 'Joined %s of %s read pairs (%.2f%%).' % (
            i - skip_count + 1, i + 1,
            float(i - skip_count + 1) / float(i + 1) * 100.0)
def main():
    #Read command line arguments
    input1_filename = sys.argv[1]
    input1_type = sys.argv[2] or 'sanger'
    input2_filename = sys.argv[3]
    input2_type = sys.argv[4] or 'sanger'
    output_filename = sys.argv[5]
    
    if input1_type != input2_type:
        print "WARNING: You are trying to join files of two different types: %s and %s." % ( input1_type, input2_type )
    
    input2 = fastqNamedReader( open( input2_filename, 'rb' ), input2_type )
    joiner = fastqJoiner( input1_type )
    out = fastqWriter( open( output_filename, 'wb' ), format = input1_type )
    
    i = None
    skip_count = 0
    for i, fastq_read in enumerate( fastqReader( open( input1_filename, 'rb' ), format = input1_type ) ):
        identifier = joiner.get_paired_identifier( fastq_read )
        fastq_paired = input2.get( identifier )
        if fastq_paired is None:
            skip_count += 1
        else:
            out.write( joiner.join( fastq_read, fastq_paired ) )
    out.close()
    
    if i is None:
        print "Your file contains no valid FASTQ reads."
    else:
        print input2.has_data()
        print 'Joined %s of %s read pairs (%.2f%%).' % ( i - skip_count + 1, i + 1, float( i - skip_count + 1 ) / float( i + 1 ) * 100.0 )
def main():
    input_filename = sys.argv[1]
    input_type = sys.argv[2] or 'sanger'
    mate1_filename = sys.argv[3]
    mate2_filename = sys.argv[4]
    single1_filename = sys.argv[5]
    single2_filename = sys.argv[6]

    type = input_type
    input = fastqNamedReader(path=input_filename, format=type)
    mate1_out = fastqWriter(path=mate1_filename, format=type)
    mate2_out = fastqWriter(path=mate2_filename, format=type)
    single1_out = fastqWriter(path=single1_filename, format=type)
    single2_out = fastqWriter(path=single2_filename, format=type)
    joiner = fastqJoiner(type)

    i = None
    skip_count = 0
    found = {}
    for i, read in enumerate(fastqReader(path=input_filename, format=type)):

        if read.identifier in found:
            del found[read.identifier]
            continue

        mate1 = input.get(read.identifier)

        mate2 = input.get(joiner.get_paired_identifier(mate1))

        if mate2:
            # This is a mate pair
            found[mate2.identifier] = None
            if joiner.is_first_mate(mate1):
                mate1_out.write(mate1)
                mate2_out.write(mate2)
            else:
                mate1_out.write(mate2)
                mate2_out.write(mate1)
        else:
            # This is a single
            skip_count += 1
            if joiner.is_first_mate(mate1):
                single1_out.write(mate1)
            else:
                single2_out.write(mate1)

    if i is None:
        print("Your input file contained no valid FASTQ sequences.")
    else:
        if skip_count:
            print('There were %i reads with no mate.' % skip_count)
        print('De-interlaced %s pairs of sequences.' % ((i - skip_count + 1) / 2))

    input.close()
    mate1_out.close()
    mate2_out.close()
    single1_out.close()
    single2_out.close()
Exemple #5
0
def main():
    input_filename = sys.argv[1]
    input_type = sys.argv[2] or 'sanger'
    mate1_filename = sys.argv[3]
    mate2_filename = sys.argv[4]
    single1_filename = sys.argv[5]
    single2_filename = sys.argv[6]

    type = input_type
    joiner = fastqJoiner(type)
    i = None
    skip_count = 0
    found = {}

    mate1_out = fastqWriter(path=mate1_filename, format=type)
    mate2_out = fastqWriter(path=mate2_filename, format=type)
    single1_out = fastqWriter(path=single1_filename, format=type)
    single2_out = fastqWriter(path=single2_filename, format=type)
    reader1 = fastqNamedReader(path=input_filename, format=type)
    reader2 = fastqReader(path=input_filename, format=type)

    with mate1_out, mate2_out, single1_out, single2_out, reader1, reader2:

        for i, read in enumerate(reader2):

            if read.identifier in found:
                del found[read.identifier]
                continue

            mate1 = reader1.get(read.identifier)

            mate2 = reader1.get(joiner.get_paired_identifier(mate1))

            if mate2:
                # This is a mate pair
                found[mate2.identifier] = None
                if joiner.is_first_mate(mate1):
                    mate1_out.write(mate1)
                    mate2_out.write(mate2)
                else:
                    mate1_out.write(mate2)
                    mate2_out.write(mate1)
            else:
                # This is a single
                skip_count += 1
                if joiner.is_first_mate(mate1):
                    single1_out.write(mate1)
                else:
                    single2_out.write(mate1)

    if i is None:
        print("Your input file contained no valid FASTQ sequences.")
    else:
        if skip_count:
            print('There were %i reads with no mate.' % skip_count)
        print('De-interlaced %s pairs of sequences.' % ((i - skip_count + 1) / 2))
Exemple #6
0
def main():
    mate1_filename = sys.argv[1]
    mate1_type = sys.argv[2] or 'sanger'
    mate2_filename = sys.argv[3]
    mate2_type = sys.argv[4] or 'sanger'
    outfile_pairs = sys.argv[5]
    outfile_singles = sys.argv[6]

    if mate1_type != mate2_type:
        print(
            "WARNING: You are trying to interlace files of two different types: %s and %s."
            % (mate1_type, mate2_type))
        return

    type = mate1_type
    joiner = fastqJoiner(type)

    nof_singles = 0
    nof_pairs = 0
    i = None
    j = None

    out_pairs = fastqWriter(path=outfile_pairs, format=type)
    out_singles = fastqWriter(path=outfile_singles, format=type)
    mate2_input = fastqNamedReader(path=mate2_filename, format=type)
    mate1_input = fastqNamedReader(path=mate1_filename, format=type)
    reader1 = fastqReader(path=mate1_filename, format=type)
    reader2 = fastqReader(path=mate2_filename, format=type)

    with out_pairs, out_singles, mate2_input, mate1_input, reader1, reader2:
        # Pairs + singles present in mate1
        for i, mate1 in enumerate(reader1):
            mate2 = mate2_input.get(joiner.get_paired_identifier(mate1))
            if mate2:
                out_pairs.write(mate1)
                out_pairs.write(mate2)
                nof_pairs += 1
            else:
                out_singles.write(mate1)
                nof_singles += 1

        # Singles present in mate2
        for j, mate2 in enumerate(reader2):
            mate1 = mate1_input.get(joiner.get_paired_identifier(mate2))
            if not mate1:
                out_singles.write(mate2)
                nof_singles += 1

    if (i is None) and (j is None):
        print("Your input files contained no valid FASTQ sequences.")
    else:
        print('There were %s single reads.' % (nof_singles))
        print('Interlaced %s pairs of sequences.' % (nof_pairs))
Exemple #7
0
def main():
    mate1_filename   = sys.argv[1]
    mate1_type       = sys.argv[2] or 'sanger'
    mate2_filename   = sys.argv[3]
    mate2_type       = sys.argv[4] or 'sanger'
    outfile_pairs    = sys.argv[5]
    outfile_singles = sys.argv[6]

    if mate1_type != mate2_type:
        print "WARNING: You are trying to interlace files of two different types: %s and %s." % ( mate1_type, mate2_type )
        return

    type = mate1_type
    joiner = fastqJoiner( type )
    out_pairs = fastqWriter( open( outfile_pairs, 'wb' ), format = type )
    out_singles = fastqWriter( open( outfile_singles, 'wb' ), format = type )

    # Pairs + singles present in mate1
    nof_singles = 0
    nof_pairs   = 0
    mate2_input = fastqNamedReader( open( mate2_filename, 'rb' ), format = type )
    i = None
    for i, mate1 in enumerate( fastqReader( open( mate1_filename, 'rb' ), format = type ) ):
        mate2 = mate2_input.get( joiner.get_paired_identifier( mate1 ) )
        if mate2:
            out_pairs.write( mate1 )
            out_pairs.write( mate2 )
            nof_pairs += 1
        else:
            out_singles.write( mate1 )
            nof_singles += 1

    # Singles present in mate2
    mate1_input = fastqNamedReader( open( mate1_filename, 'rb' ), format = type )
    j = None
    for j, mate2 in enumerate( fastqReader( open( mate2_filename, 'rb' ), format = type ) ):
        mate1 = mate1_input.get( joiner.get_paired_identifier( mate2 ) )
        if not mate1:
            out_singles.write( mate2 )
            nof_singles += 1

    if (i is None) and (j is None):
        print "Your input files contained no valid FASTQ sequences."
    else:
        print 'There were %s single reads.' % ( nof_singles )
        print 'Interlaced %s pairs of sequences.' % ( nof_pairs )

    mate1_input.close()
    mate2_input.close()
    out_pairs.close()
    out_singles.close()
Exemple #8
0
def main():
    # Read command line arguments
    input1_filename = sys.argv[1]
    input1_type = sys.argv[2] or 'sanger'
    input2_filename = sys.argv[3]
    input2_type = sys.argv[4] or 'sanger'
    output_filename = sys.argv[5]

    fastq_style = sys.argv[6] or 'old'

    paste = sys.argv[7] or ''
    # --
    if input1_type != input2_type:
        print(
            "WARNING: You are trying to join files of two different types: %s and %s."
            % (input1_type, input2_type))

    if fastq_style == 'new':
        sep = sniff_sep(input1_filename)
        joiner = FastqJoiner(input1_type, sep=sep, paste=paste)
    else:
        joiner = fq.fastqJoiner(input1_type, paste=paste)
    # --
    i = None
    skip_count = 0

    writer = fq.fastqWriter(path=output_filename, format=input1_type)
    reader1 = fq.fastqReader(path=input1_filename, format=input1_type)
    reader2 = fq.fastqNamedReader(path=input2_filename, format=input2_type)

    with writer, reader1, reader2:
        for i, fastq_read in enumerate(reader1):
            identifier = joiner.get_paired_identifier(fastq_read)
            fastq_paired = reader2.get(identifier)
            if fastq_paired is None:
                skip_count += 1
            else:
                writer.write(joiner.join(fastq_read, fastq_paired))

        # this indent is correct: we still need access to reader2
        if i is None:
            print("Your file contains no valid FASTQ reads.")
        else:
            print(reader2.has_data())
            print('Joined %s of %s read pairs (%.2f%%).' %
                  (i - skip_count + 1, i + 1,
                   (i - skip_count + 1) / (i + 1) * 100.0))
def main():
    # Read command line arguments
    input1_filename = sys.argv[1]
    input1_type = sys.argv[2] or 'sanger'
    input2_filename = sys.argv[3]
    input2_type = sys.argv[4] or 'sanger'
    output_filename = sys.argv[5]

    fastq_style = sys.argv[6] or 'old'

    paste = sys.argv[7] or ''
    # --
    if input1_type != input2_type:
        print("WARNING: You are trying to join files of two different types: %s and %s." % (input1_type, input2_type))

    if fastq_style == 'new':
        sep = sniff_sep(input1_filename)
        joiner = FastqJoiner(input1_type, sep=sep, paste=paste)
    else:
        joiner = fq.fastqJoiner(input1_type, paste=paste)
    # --
    input2 = fq.fastqNamedReader(path=input2_filename, format=input2_type)
    out = fq.fastqWriter(path=output_filename, format=input1_type)
    i = None
    skip_count = 0
    for i, fastq_read in enumerate(fq.fastqReader(path=input1_filename, format=input1_type)):
        identifier = joiner.get_paired_identifier(fastq_read)
        fastq_paired = input2.get(identifier)
        if fastq_paired is None:
            skip_count += 1
        else:
            out.write(joiner.join(fastq_read, fastq_paired))
    out.close()

    if i is None:
        print("Your file contains no valid FASTQ reads.")
    else:
        print(input2.has_data())
        print('Joined %s of %s read pairs (%.2f%%).' % (i - skip_count + 1, i + 1, (i - skip_count + 1) / (i + 1) * 100.0))