<jupyter_start><jupyter_text>creating a function to extract all the coverage depths for the alignments I want in this directory ---  1 - messing around with `os` module to get file naming correct<jupyter_code>import os
import sys
#dir(os.path)
ls
!cat bam_files.txt
base = os.path.basename('./SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29-alignment--norc-a-v2-p4/SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29--norc-a-v2-p4.sorted.bam')
base

directory = os.path.dirname('./SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29-alignment--norc-a-v2-p4/SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29--norc-a-v2-p4.sorted.bam')
directory
full = os.path.join(directory,base)
full
import subprocess
# dir(subprocess)
os.path.splitext(base)<jupyter_output><empty_output><jupyter_text>the `.sorted.bam` is a problem.  Just split the string on `.` instead of using `os` module<jupyter_code>base.split('.')<jupyter_output><empty_output><jupyter_text>---  2 - make the bedtools function and run on each file in my file list  shell command: `bedtools genomecov -d -ibam [sorted bam file] | gzip > [file.tsv.gz]`<jupyter_code>def genomecov(filename):
    base = os.path.basename(filename)
    basenoext = base.split('.')[0]
    directory = os.path.dirname(filename)
    subprocess.call('bedtools genomecov -d -ibam {} | gzip > {}'.format(filename, os.path.join(directory, basenoext + '-cov_dep.tsv.gz')), shell = True)
    
files = ['./SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29-alignment--norc-a-v2-p4/SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29--norc-a-v2-p4.sorted.bam',
'./SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29-alignment--norc-k1-v2-p4/SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29--norc-k1-v2-p4.sorted.bam',
'./SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29-alignment--norc-v2-p4-m1/SRR948553_BBduk2_NEBtrim-rRNA-bbmap_trim_29--norc-v2-p4-m1.sorted.bam',
'./SRR948555_BBduk2_NEBtrim-rRNA-bbmap_trim_29-alignment--norc-a-v2-p4/SRR948555_BBduk2_NEBtrim-rRNA-bbmap_trim_29--norc-a-v2-p4.sorted.bam',
'./SRR948555_BBduk2_NEBtrim-rRNA-bbmap_trim_29-alignment--norc-k1-v2-p4/SRR948555_BBduk2_NEBtrim-rRNA-bbmap_trim_29--norc-k1-v2-p4.sorted.bam',
'./SRR948555_BBduk2_NEBtrim-rRNA-bbmap_trim_29-alignment--norc-v2-p4-m1/SRR948555_BBduk2_NEBtrim-rRNA-bbmap_trim_29--norc-v2-p4-m1.sorted.bam']
genomecov(files[0])
for i in files:
    genomecov(i)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14364876385336744, 'fraction_numerical': 0.08013640238704177, 'mean_word_length': 5.3432432432432435, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '625726', 'license': 'MIT', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1084, 'n_words': 118, 'path': 'extract_coverages.ipynb', 'repo_name': 'jacksonh1/transcriptome_footprint_correlation', 'size': '2346'}