BCFtools fails to read regions inside nested while loop / for loop

21 Views Asked by At

I'm trying to read a file which contains:

chr2:1-26910392
chr2:26910393-53820784
chr2:53820785-80731176
chr2:80731177-107641568

Then read line per line to filter a vcf file

I'm using

count=0
for i in 2; do
    while IFS= read -r line; do
    ((count+=1))
    echo "$i"
    echo "$line"
    echo "$count"
    bcftools view -Oz --regions $line /scratch4/chr"$i"_nsconcat2.ALLChr.vcf.gz > /scratch4/split_contig/split_"$count"_"$i"_nsconcat2.ALLChr.vcf.gz
    done < /scratch4/chr"$i".txt
done

I get:

Failed to read the regions: chr2:1-26910392
[E::_regions_init_string] Could not parse the region(s): chr2:1-26910392

I tried with IFS= and IFS=/n

But when inputing everything manually, it works:

 bcftools view -Oz --regions chr2:1-26910392  /scratch4/chr2_nsconcat2.ALLChr.vcf.gz >/scratch4/split_contig/split_0_2_nsconcat2.ALLChr.vcf.gz

Echos are working fine and outputting the correct result, so I'm not sure what the problem is

Echo output:

2
chr2:1-26910392
0
2
chr2:26910393-53820784
1
2
chr2:53820785-80731176
3
2
chr2:80731177-107641568
4

I also observed that when using:

while IFS= read -r line || [[ -n "$line" ]]; do

The last line of output runs (chr2:80731177-107641568). I reverified my txt file and it is composed of one string per line, simply.

0

There are 0 best solutions below