This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Convert .Txt Into Bed Files

I used paired-end sequence data for copy number variation study; and eventually get .txt files as output. I'm hoping to use Bedtools to compare my results with others.

Can I convert .txt files into .bed files? (I don't see option in Bedtools)

If Bedtools is not working, what software can I use for data comparison?

my lines of txt is just like:

deletion    chr9:6169901-6173000    3100
deletion    chr9:7657401-7658800    1400
deletion    chr9:8847501-8848600    1100
deletion    chr9:10010201-10011600    1400
deletion    chr9:10126601-10127700    1100

thx

edit: I converted the txt files into bedpe format, which looks like

chr21    18542801    18543500
chr21    18545701    18545900
chr21    19039901    19040600
chr21    19164301    19169400
chr21    19366001    19370200
chr21    19639601    19640300
chr21    20493701    20495700
chr21    20581401    20583000
chr21    20880901    20882700
chr21    21558601    21559700

Then I started to compare two bedpe, looking for overlapping region, using the command like:

pairToPair -a 1.bedpe -b 2.bedpe > share.bedpe

Then I see the errors:

It looks as though you have less than 6 columns.  Are you sure your files are tab-delimited?

MY bed file have only three columns, seems it requires 6....What's the problem here? thx

comparison bedtools

Can you give a few sample lines from your .txt file?

2 answers

If you are on a unix or mac system the following command will convert to bed.

awk '{gsub(/[:-]/, "\t", $2); print $2}' infile.txt > outfile.bed

hi but i got another problem........can you have a look at my edit? thx

I guess pairToPair may be looking for strand information. You can add a dummy column to bring it to 6 since that information is not there in the txt file. awk '{gsub(/[:-]/, "\t", $2); print $2 "\t" $1 "\t0\t+" }' infile.txt > outfile.bed

The .bed you made is not a paired end bed, which is what the pairToPair operation calls for.

Look in the manual; a paired end bed has the start and stop coordinates of a read 1 and a read 2. You don't have that, and it doesn't look appropriate for what you want to do anyway.

I think intersectBed is probably what you want to be running; to compare your observed CNVs with other CNVs. That'll take your plain bed format.

thx! this makes more sense to me now!

Log in to answer this question.