1
$\begingroup$

I have a bed file like this:

chr1    12227   12612   LOC102725121    0   +
chr1    12721   13220   LOC102725121    0   +
chr1    12227   12612   DDX11L1 0   +
chr1    12721   13220   DDX11L1 0   +
chr1    14829   14969   WASH7P  0   -
chr1    15038   15795   WASH7P  0   -
chr1    15947   16606   WASH7P  0   -
chr1    16765   16857   WASH7P  0   -
chr1    17055   17232   WASH7P  0   -
chr1    17368   17605   WASH7P  0   -

I am trying to convert into gtf file for downstream analysis. Gtf file should look like this:

chr1   myIntrons   feature 3073253   3074322   .   +   .     gene_id "intron1"; transcript_id "intron1"
chr1   myIntrons   feature 3075858   3079636   .   +   .     gene_id "intron2"; transcript_id "intron2"

For the gene_id part in the 9th column in the double quotes I want my 4th column and in transcript_id I want combination of column1,column2,and column3 so that my output looks like this: Showing for the first line

chr1    myIntrons   intron  12228   12612   .   +   .   gene_id "LOC102725121"; transcript_id "chr1:12227-12612"

I am using this code but under double quotes it is not expanding $1 $2 etc

awk -v OFS="\t" '{print $1,"myIntrons","intron", $2+1, $3, ".", $6, ".", "gene_id $4; transcript_id $1:$2-$3"}' file.bed| head
$\endgroup$

1 Answer 1

2
$\begingroup$

Instead of the "gene_id ..." bit, you want sprintf("gene_id \"%s\"; transcript_id \"%s:%s-%s\"", $4, $1, $2, $3).

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.