For loop for MUMmer
1
0
Entering edit mode
5 months ago
Ambika ▴ 50

Hello everyone,

I am trying to run MUMmer codes in a list of files for which I tried to make a for loop, but this does not seem to work. Below are my codes and list of files:

#list of files

files=cat file_list.txt

for  var in $files do promer --mum --prefix=Nechacore-${var} 77-13-4_masked_core.fasta ${var}_AssemblyScaffolds_Repeatmasked.fasta delta-filter -g Nechacore-${var}.delta > Nechacore-${var}-filtered.delta show-coords -rcl Nechacore-${var}-filtered.delta > Nechacore-${var}.coords  I want the output files with the following names for each different input files in each steps but that's not what I am getting Nechacore-T2.delta Nechacore-T2-filtered.delta Nechacore-T2.coords Nechacore-T161.delta .., etc  Please help!! Thanks shell bash forloop • 411 views ADD COMMENT 1 Entering edit mode then what is the output you are getting? I would personally already change the loop to this: for var in cat file_list.txt do  ADD REPLY 0 Entering edit mode I am getting the delta file as below Nechacore-T2_AssemblyScaffolds_Repeatmasked.fasta-filtered.delta  instead of Nechacore-T2-filtered.delta  but after this step, I am getting an error : ERROR: Could not parse delta file, Nechacore-T2_AssemblyScaffolds_Repeatmasked.fasta.delta error no: 400 ERROR: Could not parse delta file, Nechacore-T2_AssemblyScaffolds_Repeatmasked.fasta-filtered.delta error no: 402  I think I am doing something wrong while calling the variable. The output files I am getting are also empty. When I run the code for individual files the code is alright. It runs perfectly, so the problem is definitely with the loop I made. ADD REPLY 1 Entering edit mode what would the cmdline for such a single job look like? the file names you are getting is exactly what has been asked for in the loop. In the loop you request to use the whole filename of the input files for the new file names. Since the last part is always the same you need to create a new var, in the loop, that contains the T2 T16 and so. Something like this : $base=${var%_*}  this will remove everything from the first _ onward and thus retain only the T parts ADD REPLY 0 Entering edit mode #running promer. this code generates delta file promer --mum --prefix=Nechacore-T2 77-13-4_masked_core.fasta T2_AssemblyScaffolds_Repeatmasked.fasta #filtering delta file delta-filter -g Nechacore-T2.delta > Nechacore-T2-filtered.delta #making coordinate file out of filtered delta file show-coords -rcl Nechacore-T2-filtered.delta > Nechacore-T2.coords  ADD REPLY 0 Entering edit mode see my post above to figure out what the difference is with what you do in the loop (top tip btw: including an echo of$var in your loop is a good idea to see what you're working with)

0
Entering edit mode

I am sorry, since I am quite new to these for loops I could not figure out how and where to put this new variable in my code so that I can get the desired output. Could you please help!!

1
Entering edit mode
$cat test.txt | while read var; do echo Nechacore-${var/_*/}; done

Nechacore-T161
Nechacore-T31
Nechacore-T299
Nechacore-T2

2
Entering edit mode
5 months ago

replace all ${var} with$base in your three cmdlines.

alternatively you can create a list that only contains those prefixes (in stead of the complete file names), for instance like this:

ls *_AssemblyScaffolds_Repeatmasked.fasta | sed 's/_.*\$//' > file_list.txt


than in your file_list file you will only have the T2 T16 things and don't have to change anything else

0
Entering edit mode

Thank you for your help, It is working now!!