parsing_quads_v2.py
def parse_fastq(r1_file, r2_file):
    '''
    Function to parse fastq file from bulk RNA-seq. 
    This code should be able to be expanded to run with the later parsing
    So it's important to make it modular. 
    '''
    # Initiate a dict for holding the parsed barcodes, key is promBC + rBC
    # value is the number of reads
    total_reads = 0
    wrong_reads = 0
    line_num = 0
    promBCrBC = {}
    with gzip.open(r1_file, 'rt') as r1:
        with gzip.open(r2_file, 'rt') as r2:
        # Call bulk plasmid parsing 
        # TODO: make it general purpose to call
            for line1,line2 in zip(r1,r2):    
                line1 = line1.rstrip("\n")
                line2 = line2.rstrip("\n")
                line_num += 1
                if line_num % 4 == 2:
                    total_reads += 1
                    # We first deal with line1 which comes from R2 of the sequencing file
                    bc_pair_info = check_bulk_plasmid_lib(line1)
                    # Get the parcode pair
                    # We then deal with line 2 which comes from R1 of the sequencer.
                    sc_info = extract_10xBCs(line2)
                    # bad cell
                    bad_trio = 'N'*16 + '\t' + 'N'*12
                    if 'bc_pair' in bc_pair_info:
                        if sc_info != bad_trio:
                            bc_pair = bc_pair_info['bc_pair']
                            bc_full = sc_info + '\t' + bc_pair
                            if bc_full not in promBCrBC:
                                promBCrBC[bc_full] = 0
                            promBCrBC[bc_full] += 1
                    # Get the stats
                    wrong_reads += bc_pair_info['wrong']
    print(f'The total number of reads is {total_reads}')
    print(f'The number of wrong is {wrong_reads}')
    df = pd.DataFrame(list(promBCrBC.items()),columns = ['bc_info','counts']) 
    df[['cellBC','umi','pBC','rBC']] = df['bc_info'].str.split('\t', expand=True)
    df = df.drop(columns=['bc_info'])
    return df

    Function to parse fastq file from bulk RNA-seq. 
    This code should be able to be expanded to run with the later parsing
    So it's important to make it modular. 
    
Function to parse fastq file from bulk RNA-seq.
This code should be able to be expanded to run with the later parsing
So it's important to make it modular.
Function to parse fastq file from bulk RNA - seq . This code should be able to be expanded to run with the later parsing So it ' s important to make it modular .
def parse_fastq(r1_file, r2_file):
    total_reads = 0
    wrong_reads = 0
    line_num = 0
    promBCrBC = {}
    with gzip.open(r1_file, 'rt') as r1:
        with gzip.open(r2_file, 'rt') as r2:
            for line1,line2 in zip(r1,r2):    
                line1 = line1.rstrip("\n")
                line2 = line2.rstrip("\n")
                line_num += 1
                if line_num % 4 == 2:
                    total_reads += 1
                    bc_pair_info = check_bulk_plasmid_lib(line1)
                    sc_info = extract_10xBCs(line2)
                    bad_trio = 'N'*16 + '\t' + 'N'*12
                    if 'bc_pair' in bc_pair_info:
                        if sc_info != bad_trio:
                            bc_pair = bc_pair_info['bc_pair']
                            bc_full = sc_info + '\t' + bc_pair
                            if bc_full not in promBCrBC:
                                promBCrBC[bc_full] = 0
                            promBCrBC[bc_full] += 1
                    wrong_reads += bc_pair_info['wrong']
    print(f'The total number of reads is {total_reads}')
    print(f'The number of wrong is {wrong_reads}')
    df = pd.DataFrame(list(promBCrBC.items()),columns = ['bc_info','counts']) 
    df[['cellBC','umi','pBC','rBC']] = df['bc_info'].str.split('\t', expand=True)
    df = df.drop(columns=['bc_info'])
    return df
def parse_fastq ( r1_file , r2_file ) : total_reads = 0 wrong_reads = 0 line_num = 0 promBCrBC = { } with gzip . open ( r1_file , 'rt' ) as r1 : with gzip . open ( r2_file , 'rt' ) as r2 : for line1 , line2 in zip ( r1 , r2 ) : line1 = line1 . rstrip ( "\n" ) line2 = line2 . rstrip ( "\n" ) line_num += 1 if line_num % 4 == 2 : total_reads += 1 bc_pair_info = check_bulk_plasmid_lib ( line1 ) sc_info = extract_10xBCs ( line2 ) bad_trio = 'N' * 16 + '\t' + 'N' * 12 if 'bc_pair' in bc_pair_info : if sc_info != bad_trio : bc_pair = bc_pair_info [ 'bc_pair' ] bc_full = sc_info + '\t' + bc_pair if bc_full not in promBCrBC : promBCrBC [ bc_full ] = 0 promBCrBC [ bc_full ] += 1 wrong_reads += bc_pair_info [ 'wrong' ] print ( f'The total number of reads is {total_reads}' ) print ( f'The number of wrong is {wrong_reads}' ) df = pd . DataFrame ( list ( promBCrBC . items ( ) ) , columns = [ 'bc_info' , 'counts' ] ) df [ [ 'cellBC' , 'umi' , 'pBC' , 'rBC' ] ] = df [ 'bc_info' ] . str . split ( '\t' , expand = True ) df = df . drop ( columns = [ 'bc_info' ] ) return df
Function to parse fastq file from bulk RNA-seq.
Function to parse fastq file from bulk RNA - seq .
'''
    Function to parse fastq file from bulk RNA-seq. 
    This code should be able to be expanded to run with the later parsing
    So it's important to make it modular. 
    ''' # Initiate a dict for holding the parsed barcodes, key is promBC + rBC # value is the number of reads # Call bulk plasmid parsing  # TODO: make it general purpose to call # We first deal with line1 which comes from R2 of the sequencing file # Get the parcode pair # We then deal with line 2 which comes from R1 of the sequencer. # bad cell # Get the stats
r1_file
r2_file