in any recent linux, the program rename is a perl script that uses perl regular expressions for renaming files but depending how complicated is to select the genes would be difficult to do this using a one-liner.
The simpler and involving less coding solution if you need to do it quick and dirty is as follow:
[update] I though your gene mapping was different. If you have only one gene per fasta and you have to files in same order for file and gene:
$ cat genes
ACMSD
ARID1B
CRYM
SMO
$ cat files.fof
Aardvark_GENES_D.fa.1
Aardvark_GENES_D.fa.2
Aardvark_GENES_D.fa.3
Aardvark_GENES_D.fa.4
Put both files in a single file each colum side by side (without excel)
$ paste files.fof genes
Aardvark_GENES_D.fa.1 ACMSD
Aardvark_GENES_D.fa.2 ARID1B
Aardvark_GENES_D.fa.3 CRYM
Aardvark_GENES_D.fa.4 SMO
Now is as simple as substitute GENES for the gene in the second column
$ paste files.fof genes | perl -lane '$gene=$F[1]; $file=$F[0]; $file=~s/\.\d+$//; ($new_name=$file)=~s/GENES/$gene/;print "mv $file $new_name"'
mv Aardvark_GENES_D.fa Aardvark_ACMSD_D.fa
mv Aardvark_GENES_D.fa Aardvark_ARID1B_D.fa
mv Aardvark_GENES_D.fa Aardvark_CRYM_D.fa
mv Aardvark_GENES_D.fa Aardvark_SMO_D.fa
For reproducibility and accountability, I like to have these commnads explicitly printed to a file and then sh them. Sometimes you don't get your script right at the first attempt, and also is good to have the commands run just for further review in case something is wrong latter in the pipeline.
=============
[old code left here just for historic purposes]
Assuming you have 8 files (two sets of 4 genes to rename)
$ perl -lane 'BEGIN{@x=qw(ACMSD ARID1B CRYM SMO)x2}; $gene=$x[$.-1];($new_name=$_)=~s/GENES/$gene/;print "mv $_ $new_name"' <(ls *.fa*) > rename_files.sh
Check the generated script (better safe than sorry)
$ cat rename_files.sh
mv Aardvark_GENES_D.fa.1 Aardvark_ACMSD_D.fa.1
mv Aardvark_GENES_D.fa.2 Aardvark_ARID1B_D.fa.2
mv Aardvark_GENES_D.fa.3 Aardvark_CRYM_D.fa.3
mv Aardvark_GENES_D.fa.4 Aardvark_SMO_D.fa.4
mv Aardvark_GENES_D.fa.5 Aardvark_ACMSD_D.fa.5
mv Aardvark_GENES_D.fa.6 Aardvark_ARID1B_D.fa.6
mv Aardvark_GENES_D.fa.7 Aardvark_CRYM_D.fa.7
mv Aardvark_GENES_D.fa.8 Aardvark_SMO_D.fa.8
And execute it
$ sh rename_files.fh
ardvark_ACMSD_D.fa.1
Aardvark_ACMSD_D.fa.5
Aardvark_ARID1B_D.fa.2
Aardvark_ARID1B_D.fa.6
Aardvark_CRYM_D.fa.3
Aardvark_CRYM_D.fa.7
Aardvark_SMO_D.fa.4
Aardvark_SMO_D.fa.8
I have left the number at the end to show that it works that intended
The real script to remove the number should use the regexp s/GENES(.+).\d$/$gene$1/
## $1 contains the text captured by the (.+) capturing block in the first part of the substitution regexp
perl -lane 'BEGIN{@x=qw(ACMSD ARID1B CRYM SMO)x2}; $gene=$x[$.-1]; ($new_name=$_)=~s/GENES(.+).\d$/$gene$1/;print "mv $_ $new_name"' <(ls *.fa.*)
mv Aardvark_GENES_D.fa.1 Aardvark_ACMSD_D.fa
mv Aardvark_GENES_D.fa.2 Aardvark_ARID1B_D.fa
mv Aardvark_GENES_D.fa.3 Aardvark_CRYM_D.fa
mv Aardvark_GENES_D.fa.4 Aardvark_SMO_D.fa
mv Aardvark_GENES_D.fa.5 Aardvark_ACMSD_D.fa
mv Aardvark_GENES_D.fa.6 Aardvark_ARID1B_D.fa
mv Aardvark_GENES_D.fa.7 Aardvark_CRYM_D.fa
mv Aardvark_GENES_D.fa.8 Aardvark_SMO_D.fa
.
==Working Example==
# simulate a list of files
$ touch Aardvark_GENES_D.fa.1 Aardvark_GENES_D.fa.2 Aardvark_GENES_D.fa.3 Aardvark_GENES_D.fa.4 Aardvark_GENES_D.fa.5 Aardvark_GENES_D.fa.6
# create a 'file of files' .fof file to iterate over them programatically (is better to do it with 'find' but this case is simply enough to use ls)
$ ls *.fa.* > files.fof
# how to create a mapping from file to genes
# - create your gene list and multiply (x operator) as many times as blocks of fa you have
# (you said that they were in blocks of 4 always in the same order)
# - use the $. (line number) to access to the array index of periodic gene names
# - create the command mv
$ perl -lane 'BEGIN{@x=qw(ACMSD ARID1B CRYM)x2}; $gene=$x[$.-1]; print "$_ -> $gene"' files.fof
Aardvark_GENES_D.fa.1 -> ACMSD
Aardvark_GENES_D.fa.2 -> ARID1B
Aardvark_GENES_D.fa.3 -> CRYM
Aardvark_GENES_D.fa.4 -> ACMSD
Aardvark_GENES_D.fa.5 -> ARID1B
Aardvark_GENES_D.fa.6 -> CRYM
# substitute the names. In perl in order to do a substitution and asign it to a new variable, you need first to create the copy and then substitute the string. If you want to do it all at once, you need to put in parents the assignment ($new_var=$ori_var), and then do the substitution `($new_var=$ori_var)=~/s/a/b/`
$ perl -lane 'BEGIN{@x=qw(ACMSD ARID1B CRYM)x2}; $gene=$x[$.-1]; ($new_name=$_)=~s/GENES/$gene/;print "mv $_ $new_name"' files.fof > rename_files.sh
Who do you know which ones to rename to CRYM or ACMSD
first one for ACMSD, Second one for ARID1B, Third one for CRYM, this will be in the same order
Your fourth file is named SMO... You need to clearly define the rule you want to use to rename your files.
Does numbers at the end of your files correspond to the order of gen names in a separate list?
Hello adeenahassan77!
This is a not a bioinformatics question and multiple solution have already been posted.
For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.
If you disagree please tell us why in a reply below, we'll be happy to talk about it.
Cheers!