I have a series of samples that will be names unique header. For instance the sample could be labeled (SC892138_CTGAAGCT-ACTCTGAG or SC892138_unisample)_L001_001.star_rg_added.sorted.dmark.bam. Or(SC892155_CTGAAGCT-ACTCTGAG or SC892155_unisample)_L001_001.star_rg_added.sorted.dmark.bam. Or some other number after SC. I can parse out SC###### value for each sample, but I want to get to this:SC892155_CTGAAGCT-ACTCTGAG. How do I parse this out?
import os
import glob
import itertools
import pandas
from collections import defaultdict
workdir: os.environ['PWD']
## ---- The parser may have to be customized for each run ---- ##
def parse_sampleID(filename):
return filename.split('/')[-1].split('_')[0]
fastqs = glob.glob('/P/A/T/H/S/*star_rg_added.sorted.dmark.bam')
d = defaultdict(list)
for key, value in itertools.groupby(fastqs, parse_sampleID):
d[key] += list(value)
# Need to modify sampleIDs to bams not R1/R2 files
sampleIDs = d.keys()