Login and get coding
In this bite you will write a function that pairs filenames with each other. This is useful in the bioinformatics field, as some of the current sequencing technologies produce two paired files for each sample which need to be processed together.
The filenames have the following naming scheme:
A pair always consists of an
The SampleName and all numbers are variable but the overall structure is always the same:-
SampleNamecan contain letters, number or special characters (including
_)- The number following
Sruns from 1 to 99- The number following
Lruns from 001 to 999-
R1stands for file 1 and
R2for file 2 of a pair (no other numbers are allowed)- The last number block runs from 001 to 999- The file name extension should end in
fastq.gz(no extra extensions such as
Your task- Write a function
pair_files(filenames)that receives a list of filenames and returns a list of tuples, where each tuple contains pairs of filenames in the following order
(filename1-R1, filename2-R2)- Ignore filenames that do not match the naming scheme (even if they contain
R2)- Matching the filenames shoulb be case insensitive but the function should return the correct case in the filename pairs- For the tests presented here, you can assume that there is at most one file that can be paired with another (no higher tuplets)
Example# Two complete pairs, one file without partner
>>> filenames = [
27 out of 28 users completed this Bite.
Will you be Pythonista #28 to crack this Bite?
Resolution time: ~83 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 4.5 on a 1-10 difficulty scale.
» Up for a challenge? 💪