awk ' BEGIN { print "chr\ttranscript_start\ttranscript_stop\ttranslation_start\ttranslation_stop\tstrand\tgene_name\ttranscript_id\ttype\texon_starts\texon_ends\tadditional_info" } { split($9, attrs, "; ") gene_id = "" transcript_id = "" gene_name = "" # Extract attributes for (i in attrs) { if (attrs[i] ~ /gene_id/) { split(attrs[i], gene, " ") gene_id = gene[2] } if (attrs[i] ~ /transcript_id/) { split(attrs[i], trans, " ") transcript_id = trans[2] } if (attrs[i] ~ /gene_name/) { split(attrs[i], name, " ") gene_name = name[2] } } if ($3 == "transcript") { transcript_start = $4 transcript_stop = $5 translation_start = "." # Placeholder translation_stop = "." # Placeholder strand = $7 # Initialize exon lists for this transcript exon_starts[transcript_id] = "" exon_ends[transcript_id] = "" # Store transcript info transcripts[transcript_id] = $1 "\t" transcript_start "\t" transcript_stop "\t" translation_start "\t" translation_stop "\t" strand "\t" gene_name "\t" transcript_id "\ttranscript" } if ($3 == "exon") { # Get the current transcript_id for (i in attrs) { if (attrs[i] ~ /transcript_id/) { split(attrs[i], trans, " ") current_transcript_id = trans[2] break } } exon_starts[current_transcript_id] = (exon_starts[current_transcript_id] ? exon_starts[current_transcript_id] "," : "") $4 exon_ends[current_transcript_id] = (exon_ends[current_transcript_id] ? exon_ends[current_transcript_id] "," : "") $5 } } END { for (trans_id in transcripts) { print transcripts[trans_id] "\t" exon_starts[trans_id] "\t" exon_ends[trans_id] "\t" "" } }' adr_gland_filtered2.gtf > output.bed