Hi,
This is my first post so please bear with me. I have about 2000 bed files that I would like to extract FASTA sequences from. I have been able to extract a single set of bed sequences using the following command:
.narrowPeak is a BED file.
bedtools getfasta -fi TAIR10_Chr.fasta -bed /copy_peaks/ABI5_col_v3h.narrowPeak > ABI5_col_v3h.fasta
within my copy_peaks folder there are 2000 other files I would like to perform this operation on. Any ideas?
The results will then be used in fimo, where again I will need to perform this operation on the extracted fasta files.
Thanks,
I'll give this a shot, all of files have the same extension. Does this also create a new file? and I was hoping for the new file to keep the name of the narrowpeak file but with .fasta as the suffix. Thanks!
The first thing the loop does is create a $r variable, which is based on the file name of the input as you can see. That $r variable is then used as output name and indeed I switch the narrowPeak to fasta and write to the current directory. Changing this should be pretty straightforward, right?
You can test the output names first using the following loop:
I ran this :
The result was: *.fasta I then attempted to run the loop as you had written it, the results were:
bash: *.fasta: No such file or directory
Please pardon all my questions, I've been stuck on this for a while now.
I assume based on this that there is no path
/copy_peaks/
. Are you sure of that path? Is it perhaps justcopy_peaks
in the current directory, and not on the root directory?Yes, copy_peaks is a folder in the current working directory, now I'm getting $r is an ambiguous redirect? Thanks - Alex
Does this look okay? Note that I changed the first line to reflect the directory in which the bed files can be found.
Your example
bedtools getfasta -fi TAIR10_Chr.fasta -bed /copy_peaks/ABI5_col_v3h.narrowPeak > ABI5_col_v3h.fasta
was then incorrect because the path to the narrowPeak file doesn't exist as such. Should have beenbedtools getfasta -fi TAIR10_Chr.fasta -bed copy_peaks/ABI5_col_v3h.narrowPeak > ABI5_col_v3h.fasta
It's worked! Thank you for your help