I have a large number of directories with unique names. Inside each directory is a contigs.fasta file. I need to rename the contigs.fasta file to include the unique directory name so that if I combine all of the contigs.fasta files I will be able to determine where each originated. For example some of the directories are listed below:
Cage1.out_bin.100_Reassembly.Spades Cage1.out_bin.125_Reassembly.Spades Cage1.out_bin.27_Reassembly.Spades Cage1.out_bin.51_Reassembly.Spades Cage1.out_bin.76_Reassembly.Spades
Cage1.out_bin.101_Reassembly.Spades Cage1.out_bin.126_Reassembly.Spades Cage1.out_bin.28_Reassembly.Spades Cage1.out_bin.52_Reassembly.Spades Cage1.out_bin.77_Reassembly.Spades
Cage1.out_bin.102_Reassembly.Spades Cage1.out_bin.127_Reassembly.Spades Cage1.out_bin.29_Reassembly.Spades Cage1.out_bin.53_Reassembly.Spades Cage1.out_bin.78_Reassembly.Spades
The contents of one directory is listed below: assembly_graph.fastg before_rr.fasta contigs.paths dataset.info K33 K77 misc scaffolds.fasta spades.log assembly_graph_with_scaffolds.gfa contigs.fasta corrected input_dataset.yaml K55 K99 params.txt scaffolds.paths tmp
How do I rename the contigs.fasta file for all the directories?
with gnu-parallel:
This would make a copy of the existing file and the new file will have .fa extension. Remove
--dry-run
to execute the command.You can also try this. Go to parent directory and run this command:
Remember this would rename all the files. Take a backup of your files. This function would dry-run the code. Remove -nv before you run the code.
For questions such as this which are more unix focused you should always check StackExchange/Stackoverflow. Here is one potential answer from Stackoverflow.