bash repeat file names if in directory after executing NGS tools
0
0
Entering edit mode
7.7 years ago
bioguy24 ▴ 230

I have some NGS data that gets processing by a variety of tools in a for loop. The end output looks like below:

00-0000_fbn1_20xcoverage.txt
01-0101_fbn1_20xcoverage.txt
02-0202_fbn1_20xcoverage.txt

Basically, what I am trying to do is add another identifier to each file matching the numerical prefix to an lines 3,4,5 of an analysis file.

analysis file contents

status: complete 
id names:  
00-0000_Last-First 
01-0101_LastN-FirstN
02-0202_La-Fi

The bash below works great if all 3 files are already in the directory, but they are added one at a time and the previous is repeating when the code executes. I can not seem to alter the code correctly so the filenames do not repeat. Thank you :).

while IFS="_" read -r id newname;do
#echo "id=$newid - newname=$newname"  #for cross check 
oldfilename=$(find . -name "${id}*.txt" -printf %f)
[ -n "$oldfilename" ] &&  mv "$oldfilename" "${id}_${newname}_${oldfilename#*_}";
done < <(tail -n+3 analysis.txt)

So if in /home/percent ---- this is the directory that I execute the code in after cd to it, should I define it in the loop?

00-0000_Last-First_fbn1_20xcoverage.txt

code executes a second time:
00-0000_Last-First_Last-First_fbn1_20xcoverage.txt  ---- file already in dir
01-0101_LastN-FirstN_fbn1_20xcoverage.txt

code executes a third time:
00-0000_Last-First_Last-First_Last-First_fbn1_20xcoverage.txt  ---- file already in dir
01-0101_LastN-FirstN_LastN-FirstNfbn1_20xcoverage.txt   --- this is the 2nd file in dir
02-0202_La-Fi_fbn1_20xcoverage.txt

desired output
 00-0000_Last-First_fbn1_20xcoverage.txt
 01-0101_LastN-FirstN_fbn1_20xcoverage.txt
 02-0202_La-Fi_fbn1_20xcoverage.txt
NGS • 1.4k views
ADD COMMENT
1
Entering edit mode

why don't you rename them after all jobs done?

ADD REPLY
0
Entering edit mode

That is what I currently do, but each of the files is processed individually so I am trying to rename that file before being saved in the directory. Alternatively, maybe a function could be used to rename all of them but the ideal would be to rename or add the text to the individual file if possible. Thank you :).

ADD REPLY
1
Entering edit mode

you may let the processer to do this or use a moniter that check file changes to rename newly added result file.

ADD REPLY
0
Entering edit mode

Thank you very much :)

ADD REPLY

Login before adding your answer.

Traffic: 1808 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6