<jupyter_start><jupyter_text>bammap creation<jupyter_code>bam_dir = '../bams/'
bam_dir = '/gscmnt/gc2686/rna_editing/TCGA-TGCT/bams/'
output_bammap = '../TCGA-TGCT.bammap'
metadata = pd.read_csv('/gscmnt/gc2686/rna_editing/sandbox/gdc_sample_sheet.2020-06-20.tsv', sep='\t')
metadata = metadata.set_index('File ID')
metadata
Counter(metadata['Sample Type']).most_common()
fps = sorted(os_helpers.listfiles(bam_dir, regex='.bam$'))
len(fps), fps[:5]
# sample_name	case	disease	experimental_strategy	sample_type	data_path	filesize	data_format	reference	UUID	system
11LU013.WGS.N.hg38	11LU013	LUAD	WGS	blood_normal	/gscmnt/gc2619/dinglab_cptac3/GDC_import/data/89783e46-3269-42ad-8b4a-6b3de3fd47dc/e04e7004-0cc8-42d0-9276-a290b24940ce_gdc_realn.bam	96565337883	BAM	hg38	89783e46-3269-42ad-8b4a-6b3de3fd47dc	MGI



d = {
    '# sample_name': [],
    'case': [],
    'disease': [],
    'experimental_strategy': [],
    'sample_type': [],
    'data_path': [],
    'filesize': [],
    'data_format': [],
    'reference': [],
    'UUID': [],
    'system': []
}
for fp in fps:
    pieces = fp.split('/')
    uuid = pieces[-2]
    case = metadata.loc[uuid, 'Case ID']
    if metadata.loc[uuid, 'Sample Type'] in ['Blood Derived Normal', 'Primary Tumor']:
        sample_type = 'blood_normal' if metadata.loc[uuid, 'Sample Type'] == 'Blood Derived Normal' else 'tumor'
        filesize = os.path.getsize(fp)
        character = 'N' if sample_type == 'blood_normal' else 'T'
        sample_name = f'{case}.WXS.{character}.hg38'

        d['# sample_name'].append(sample_name)
        d['case'].append(case)
        d['disease'].append('TGCT')
        d['experimental_strategy'].append('WXS')
        d['sample_type'].append(sample_type)
        d['data_path'].append(fp)
        d['filesize'].append(filesize)
        d['data_format'].append('BAM')
        d['reference'].append('hg38')
        d['UUID'].append(uuid)
        d['system'].append('MGI')
bammap = pd.DataFrame.from_dict(d)
bammap
    
    
bammap.to_csv(output_bammap, sep='\t', index=False, header=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1716203259827421, 'fraction_numerical': 0.055129434324065196, 'mean_word_length': 3.922169811320755, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '549535', 'license': 'MIT', 'n_tokens_mistral': 902, 'n_tokens_neox': 819, 'n_words': 118, 'path': 'make_bammap.ipynb', 'repo_name': 'estorrs/somaticwrapper-notebooks', 'size': '2086'}