<jupyter_start><jupyter_text>Barcode distribution within 2 indipendet chromatin poolings (S2 cells)<jupyter_code>%%bash

merged_fastq_folder="/data/deepseq/sequencing_data/191111_A00931_0028_AHH7JGDRXX_lanes1_2/Project_1146_Bella_DeepSeq"

### Extracts barcodes from merged input ###

for i in $merged_fastq_folder/Sample_19L005189/Input_60_BCs_rep_4_R1.fastq.gz; do zcat $i | awk '/^@/{getline;print}' | cut -c5-12 > ../intermediate_files/$(basename $i)_barcodes_R1.txt; done
for i in $merged_fastq_folder/Sample_19L005191/Rep_Input_60_BCs_rep_4_R1.fastq.gz; do zcat $i | awk '/^@/{getline;print}' | cut -c5-12 > ../intermediate_files/$(basename $i)_barcodes_R1.txt; done

### read in barcodes metadata ###

list_barcodes = []
mapp = {}
with open("../input_data/1146_Bella_DeepSeq.txt") as inp:
    for line in inp:
        bc = line.strip().split()[1]
        sample = line.strip().split()[2]
        if not bc in list_barcodes:
            list_barcodes.append(bc)
            mapp[bc] = sample
        else:
            pass
print("Total number of barcodes: {}".format(len(list_barcodes)))



### count and plot ###

ranks = []
input_dir = "../intermediate_files"

for filename in os.listdir(input_dir):
    if filename.startswith("Input") or filename.startswith("Rep"):
        #count_line=0
        dixio={}
        with open(os.path.join(input_dir,filename)) as inp:
            for line in inp:
                #count_line+=1
                barcode = line.strip()
                if not barcode in dixio:
                    dixio[barcode] = 1
                else:
                    dixio[barcode]+=1
                    
        final_dixio={}
        sig_barcodes = {}
        for i in dixio:
            final_dixio[i] = dixio[i]/count_line
            if (dixio[i]/count_line)*100 > 0.1:
                sig_barcodes[i] = (dixio[i]/count_line)*100
                
        barcodes = []
        fraction = []
        gc_content = []
        for i in sig_barcodes:
            barcodes.append(i)
            fraction.append(sig_barcodes[i])
            gc_content.append(float(float(i.count("G")) + float(i.count("C")))/float(len(i)))
    
        fdf = pd.DataFrame({"barcodes":barcodes, "fraction":fraction, "gc_content":gc_content})
        fdf.sort_values(by="fraction", ascending=False, inplace=True)
        fdf["ID"] = ["_".join(mapp[i].split("_")[:2]) if i in mapp else i for i in fdf.barcodes]
        ranks.append(fdf)

        ### plot ###
        
        called_barcodes = []
        fig,ax = plt.subplots(dpi=300,figsize=(10,2))
        ax.bar(range(len(barcodes)), np.array(fdf.fraction))
        ax.set_xticks(range(len(barcodes)))
        ax.set_xticklabels(fdf.ID,rotation=45, ha="right", size=7)
        plt.ylabel("% of total\ninput reads")
        for i in range(len(list(fdf.barcodes))):
            if list(fdf.barcodes)[i] in list_barcodes:
                called_barcodes.append(list(fdf.barcodes)[i])
                #ax.get_xticklabels()[i].set_color("k")

        ax.spines['right'].set_visible(False)
        ax.spines['top'].set_visible(False)

        # Only show ticks on the left and bottom spines
        ax.yaxis.set_ticks_position('left')
        ax.xaxis.set_ticks_position('bottom')
        
        ax.axhline(100/60, linestyle="--", linewidth=0.5, color='k')
        
        xx = [-2,-1]+list(range(len(barcodes)))+[len(barcodes)+1,len(barcodes)+2]
        
        yy = fdf.fraction.copy()
        mmean = np.mean(yy)
        yy = (yy - (100/60))

        std = np.std(yy)
        ax.fill_between(xx, [mmean + std]*len(xx), [mmean - std]*len(xx), 
                        color='dimgrey', alpha=0.2, zorder=3)
        
        
        plt.tight_layout()
        plt.savefig("../figures/Barcode_integration_efficiency_{}.pdf".format(filename.split(".")[0]))<jupyter_output>Total number of barcodes: 60
{'fraction_non_alphanumeric': 0.147485743908761, 'fraction_numerical': 0.027475375842405392, 'mean_word_length': 2.427175843694494, 'pattern_counts': {'":': 3, '<': 4, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '566039', 'license': 'MIT', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1338, 'n_words': 222, 'path': 'figure_1/notebooks/1b_barcode_distribution.ipynb', 'repo_name': 'FrancescoFerrari88/AutoRELACS', 'size': '3858'}