Bedtools loop over subfolders
1
0
Entering edit mode
2.2 years ago
cwang130 • 0

Hello,

I want to use bedtools intersect to compare multiple pairs of files. For example, I have folder1, and file1 and file2 in it and then folder2, file3 and file4 in it etc. I want to find a way that do all these comparison in a loop or with pipe '|' .

I know how to do this with one pair , like bedtools intesect -a file1 -b file2. Then how can I do this if I have 90 pairs of files and they are all different samples?

If I want to use ls | xargs bedtools intersect , it is still won't work. or how can I tell each -a -b position the correct standard input or argument from previous one?

I hope I stated my questions clearly enough and appreciate any idea. Thanks.

Bedtools • 869 views
ADD COMMENT
0
Entering edit mode
2.2 years ago
Asaf 10k

You can use bash for loops. The syntax is:

for f1 in $(ls dir1/); do for f2 in $(ls dir2/); do bedtools intersect -a $f1 -b $f2 ; done ; done 

You'll to do some work to set the output file names though

ADD COMMENT
0
Entering edit mode

Thanks for the reply. However, I have the two files in dir1 which I want to compare. file1 ad file2 are in the same folder. Then I don't think this will work for my case. But it provided a solution. I will try to work more on it.

ADD REPLY
0
Entering edit mode

You can put any bash command in the $() so you can ls certain files, grep or do whatever you like.

The best choice, however, is to take the time and implement it as a nextflow or snakemake pipeline, future you will thank you when you'll have to repeat it in the future because you found a small bug, changed the input files or just wanted to publish a reproducible analysis.

ADD REPLY

Login before adding your answer.

Traffic: 1653 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