I'm trying to figure out how to use regex to parse out fields from a naming scheme.
For example, here are 3 different naming schemes:
ns1 = "[ID]_R[DIRECTION].fastq.gz"
ns2 = "[ID]_R[DIRECTION]_001.fastq"
ns3 = "barcode-[ID]_[DIRECTION].fq"
Here is a query for naming scheme 1 (ns1):
query1_ns1 = "Kuwait_110_S59_R1.fastq.gz"
ID = "Kuwait_110_S59"
DIRECTION = "1"
query2_ns1 = "Kuwait_110_S59_R2.fastq.gz"
ID = "Kuwait_110_S59"
DIRECTION = "2"
Here is a query for naming scheme 2 (ns2):
query1_ns1 = "Kuwait_110_S59_R1_001.fastq.gz"
ID = "Kuwait_110_S59"
DIRECTION = "1"
query2_ns1 = "Kuwait_110_S59_R2_001.fastq.gz"
ID = "Kuwait_110_S59"
DIRECTION = "2"
Here is a query for naming scheme 3 (ns3):
query1_ns1 = "barcode-Kuwait_110_S59_1.fq"
ID = "Kuwait_110_S59"
DIRECTION = "1"
query2_ns1 = "barcode-Kuwait_110_S59_2.fq"
ID = "Kuwait_110_S59"
DIRECTION = "2"
How can I use regex in Python to parse out fields in this context?
My current method is to do a series of splitting events on a string which doesn't seem like the best option.
source https://stackoverflow.com/questions/73296040/how-to-parse-out-two-fields-out-of-string-using-regex-in-python
Comments
Post a Comment