After 4.1 years...
Hi @mxs, thanks for the script. For some reason, I was getting an error in the result. I modified your script slightly. Below are the steps:
$ cat test2.txt
>NZ_CP025963.1
ATGCAGTNNNACGTGCATGACTGTACGTANGTACGTGACTGACTGACTGACTNACTGACTGATCGTACNTACGTAC
$ perl -ne 'chomp;if( />(.*)/){$head = $1; $i=0; next};@a=split("",$_); foreach(@a){$i++;if($_ eq "N" && $s ==0 ){print "$head\t$i"; $s =1}elsif($s==1 && $_ ne "N"){print "\t$i\n";$s=0}}' test2.txt
NZ_CP025963.1 8 11
NZ_CP025963.1 30 31
NZ_CP025963.1 53 54
NZ_CP025963.1 69 70
$ cat >test2.bed
NZ_CP025963.1 8 11
NZ_CP025963.1 30 31
NZ_CP025963.1 53 54
NZ_CP025963.1 69 70
$ bedtools getfasta -fi test2.txt -bed test2.bed
index file test2.txt.fai not found, generating...
>NZ_CP025963.1:8-11
NNA
>NZ_CP025963.1:30-31
G
>NZ_CP025963.1:53-54
A
>NZ_CP025963.1:69-70
T
Instead of giving me the regions of N's, oneliner have extracted other regions also. Or may be it is because bedtools is zero based system.
Modified version:
$ perl -ne 'chomp;if( />(.*)/){$head = $1; $i=0; next};@a=split("",$_); foreach(@a){$i++; if($_ eq "N" && $s ==0 ){$z=$i-1; print "$head\t$z"; $s =1}elsif($s==1 && $_ ne "N"){$j=$i-1;print "\t$j\n";$s=0}}' test2.txt
NZ_CP025963.1 7 10 ("7" here is zero based coordinate and "10" is 1 based coordinate)
NZ_CP025963.1 29 30
NZ_CP025963.1 52 53
NZ_CP025963.1 68 69
$ bedtools getfasta -fi test2.txt -bed test2.bed
>NZ_CP025963.1:7-10
NNN
>NZ_CP025963.1:29-30
N
>NZ_CP025963.1:52-53
N
>NZ_CP025963.1:68-69
N
More info on zerobased and one-based system is here.
may be you're looking for http://hgdownload.cse.ucsc.edu/goldenPath/hg19/database/gap.txt.gz ?
Thank you, I think that resolve my problem.