Remember I am new at Perl, so my approach is probably pretty brutish.
Input:
==> igenome.genes.onlyexons.uniq.gtf <==
chr1 unknown exon1 815 4692 . - . gene_id "LOC
+653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id "
+TSS10265";
chr1 unknown exon2 4833 4901 . - . gene_id "LO
+C653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id
+"TSS10265";
chr1 unknown exon3 5659 5810 . - . gene_id "LO
+C653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id
+"TSS10265";
chr1 unknown exon4 6470 6628 . - . gene_id "LO
+C653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id
+"TSS10265";
chr1 unknown exon5 6717 6918 . - . gene_id "LO
+C653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id
+"TSS10265";
chr1 unknown exon6 7096 7231 . - . gene_id "LO
+C653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id
+"TSS10265";
chr1 unknown exon7 7469 7605 . - . gene_id "LO
+C653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id
+"TSS10265";
chr1 unknown exon8 7778 7924 . - . gene_id "LO
+C653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id
+"TSS10265";
chr1 unknown exon9 8131 8229 . - . gene_id "LO
+C653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id
+"TSS10265";
chr1 unknown exon10 8776 8938 . - . gene_id "L
+OC653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_id
+ "TSS10265";
chr1 unknown exon11 14601 14754 . - . gene_id
+"LOC653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_
+id "TSS10265";
chr1 unknown exon12 19184 19919 . - . gene_id
+"LOC653635"; gene_name "LOC653635"; transcript_id "XR_017611.2"; tss_
+id "TSS10265";
chr1 unknown exon13 58954 59871 . + . gene_id
+"OR4F5"; gene_name "OR4F5"; p_id "P1363"; transcript_id "NM_001005484
+.1"; tss_id "TSS13645";
chr1 unknown exon14 77385 80096 . + . gene_id
+"LOC100132632"; gene_name "LOC100132632"; p_id "P27379"; transcript_i
+d "XM_001724183.1"; tss_id "TSS10177";
chr1 unknown exon15 110381 110795 . - . gene_i
+d "LOC643670"; gene_name "LOC643670"; transcript_id "XR_039242.1"; ts
+s_id "TSS5420";
chr1 unknown exon16 114643 114701 . - . gene_i
+d "LOC729737"; gene_name "LOC729737"; p_id "P4208"; transcript_id "XM
+_001133863.1"; tss_id "TSS9238";
chr1 unknown exon17 118918 119086 . - . gene_i
+d "LOC643670"; gene_name "LOC643670"; transcript_id "XR_039242.1"; ts
+s_id "TSS5420";
chr1 unknown exon18 123237 130714 . - . gene_i
+d "LOC643670"; gene_name "LOC643670"; transcript_id "XR_039242.1"; ts
+s_id "TSS5420";
chr1 unknown exon19 123324 130714 . - . gene_i
+d "LOC653340"; gene_name "LOC653340"; transcript_id "XR_039243.1"; ts
+s_id "TSS5420";
chr1 unknown exon20 129326 129559 . - . gene_i
+d "LOC729737"; gene_name "LOC729737"; p_id "P4208"; transcript_id "XM
+_001133863.1"; tss_id "TSS9238";
chr1 unknown exon21 129653 129710 . - . gene_i
+d "LOC729737"; gene_name "LOC729737"; p_id "P4208"; transcript_id "XM
+_001133863.1"; tss_id "TSS9238";
chr1 unknown exon22 132810 132874 . - . gene_i
+d "LOC729737"; gene_name "LOC729737"; p_id "P4208"; transcript_id "XM
+_001133863.1"; tss_id "TSS9238";
chr1 unknown exon23 133719 134341 . - . gene_i
+d "LOC729737"; gene_name "LOC729737"; p_id "P4208"; transcript_id "XM
+_001133863.1"; tss_id "TSS9238";
chr1 unknown exon24 217633 218641 . - . gene_i
+d "LOC728481"; gene_name "LOC728481"; transcript_id "XR_015292.2"; ts
+s_id "TSS13278";
chr1 unknown exon25 313133 319752 . + . gene_i
+d "LOC100132287"; gene_name "LOC100132287"; transcript_id "XR_039254.
+1"; tss_id "TSS18904";
#!/usr/bin/perl -w
use strict;
my $previous = '';
my $exon = 1;
while (<>) {
chomp;
my(@gtf) = split;
chop($gtf[8] = join ":", @gtf[8,9]);
chop($gtf[10] = join ":", @gtf[10,11]);
chop($gtf[12] = join ":", @gtf[12,13]);
# Restart exon# for different gene names
if ( $gtf[9] ne $previous ) {
$gtf[2] = 'exon1';
} elsif ( $gtf[9] eq $previous ) {
$exon =~ s/(\d+)/$1+1/e;
}
$previous = $gtf[9];
$exon = $gtf[2];
$gtf[8] = join "_", @gtf[8,10,12,2];
my $bed = join "\t", @gtf[0,3,4,8];
print "$bed\n";
}
Here's 25 lines of the output (I'll bold the lines where the problem appears and simplify the data for formatting by removing array items 10 and 12):
chr1 815 4692 gene_id:"LOC653635"_exon1
chr1 4833 4901 gene_id:"LOC653635"_exon2
chr1 5659 5810 gene_id:"LOC653635"_exon3
chr1 6470 6628 gene_id:"LOC653635"_exon4
chr1 6717 6918 gene_id:"LOC653635"_exon5
chr1 7096 7231 gene_id:"LOC653635"_exon6
chr1 7469 7605 gene_id:"LOC653635"_exon7
chr1 7778 7924 gene_id:"LOC653635"_exon8
chr1 8131 8229 gene_id:"LOC653635"_exon9
chr1 8776 8938 gene_id:"LOC653635"_exon10
chr1 14601 14754 gene_id:"LOC653635"_exon11
chr1 19184 19919 gene_id:"LOC653635"_exon12
chr1 58954 59871 gene_id:"OR4F5"_exon1
chr1 77385 80096 gene_id:"LOC100132632"_exon1
chr1 110381 110795 gene_id:"LOC643670"_exon1
chr1 114643 114701 gene_id:"LOC729737"_exon1
chr1 118918 119086 gene_id:"LOC643670"_exon1
chr1 123237 130714 gene_id:"LOC643670"_exon18
chr1 123324 130714 gene_id:"LOC653340"_exon1
chr1 129326 129559 gene_id:"LOC729737"_exon1
chr1 129653 129710 gene_id:"LOC729737"_exon21
chr1 132810 132874 gene_id:"LOC729737"_exon22
chr1 133719 134341 gene_id:"LOC729737"_exon23
chr1 217633 218641 gene_id:"LOC728481"_exon1
chr1 313133 319752 gene_id:"LOC100132287"_exon1
The bolded lines should count up from 1, for example, "exon18" should read "exon2" and exon21, exon 22, exon23 should read exon2, exon3, exon4.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.