Skip to content

Instantly share code, notes, and snippets.

@epaule
Last active February 20, 2019 11:29
Show Gist options
  • Save epaule/b1fdf825b85884f3df153f9d63dd6069 to your computer and use it in GitHub Desktop.
Save epaule/b1fdf825b85884f3df153f9d63dd6069 to your computer and use it in GitHub Desktop.
fiddles with the GFF3 mRNA spans based on CDSes
#!/usr/bin/env perl
my $inf = shift;
open IN, $inf;
my %cds;
# slurpy block
while (<IN>){
chomp;
my @F = split;
if (/Parent=([^;]+)/){
my $id = "$1";
$cds{$id}->{start}||=$F[3];
$cds{$id}->{stop}||=$F[4];
$cds{$id}->{start}=$F[3] if $F[3] < $cds{$id}->{start};
$cds{$id}->{stop}=$F[4] if $F[4] > $cds{$id}->{stop};
}
}
close IN;
# fixie block
# while (my ($k,$v)= eadch %cds){
# print "funky "
# }
open IN, $inf;
while (<IN>){
if (/ID=([^;\n]+)/){
my @F=split;
my ($newStart,$newStop) = ($cds{$1}->{start},$cds{$1}->{stop});
my ($oldStart,$oldStop) = ($F[3],$F[4]);
s/$oldStart/$newStart/;
s/$oldStop/$newStop/;
}
print
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment