My apologies if a similar question has been asked before. I am struggling to find a solution to my problem. We are receiving a number of sequencing files (fastq) from an MGI sequencer. The default naming scheme for each library that is sequenced is
V350012345_L01_49_1.fq.gz
V350012345_L01_49_2.fq.gz
V350012345_L01_95_1.fq.gz
V350012345_L01_95_2.fq.gz
Each library is denoted by the default index number of the system i.e 49 and 95 in the above example. I would like to rename these using a tsv to replace the index number with the actual sample number using a tsv file as an input. eg.
V350012345_L01_sample1_1.fq.gz
V350012345_L01_sample1_2.fq.gz
V350012345_L01_sample2_1.fq.gz
V350012345_L01_sample2_2.fq.gz
I do have a file with the index number and sample name and have tried to rename using the following bash command without any success.
tsv file:
49 sample1
95 sample2
command:
while read -r id name; do rename 's/"$id"/"name"/g' *.fq.gz; done < sample.tsv
Any pointers in the right direction will be appreciated as I am currently learning bash
The solution from Matthias Zepper will work, but I want to recommend to you (in line with his first sentence) that whenever you rename original files then either be sure to make a copy first in case something crashes or gets overwritten or, preferred, make a separate folder, symlink (
ln -s
) the original files into it and test with that the command first or simply use the symlinked files as input for your analysis. In any case, make sure that the "rawrawraw" files from the sequencing company are somewhere, save and untouched.I don't have a command line solution for you, but my solution would involve python and using os.system to write various
mv
commands to rename your files.Thanks for the reply. I am open to learning python as well. I am interested in your solution