Skip to content

Commit

Permalink
Merge pull request nf-core#603 from atrigila/issue_602
Browse files Browse the repository at this point in the history
Add missing script in local module `GET_RRNA_TRANSCRIPTS`
  • Loading branch information
atrigila authored Dec 27, 2024
2 parents c63fcb7 + 856449d commit f6cdcf6
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 233 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed bug in nf-core `RRNATRANSCRIPTS` module [#563](https://github.com/nf-core/rnafusion/issues/563)
- Fixed bug in `GFFREAD` that caused output `gffread_fasta` not being produced [#565](https://github.com/nf-core/rnafusion/issues/565)
- Fixed bug in `FUSIONCATCHER_DOWNLOAD` that caused an error when running with singularity profile [#573](https://github.com/nf-core/rnafusion/issues/573)
- Fixed missing script `gtf2bed` which caused local module `GET_RRNA_TRANSCRIPTS` to fail [#602](https://github.com/nf-core/rnafusion/issues/602)

### Removed

Expand Down
123 changes: 123 additions & 0 deletions bin/gtf2bed
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env perl

# Copyright (c) 2011 Erik Aronesty ([email protected])
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ALSO, IT WOULD BE NICE IF YOU LET ME KNOW YOU USED IT.

use Getopt::Long;

my $extended;
GetOptions("x"=>\$extended);

$in = shift @ARGV;

my $in_cmd =($in =~ /\.gz$/ ? "gunzip -c $in|" : $in =~ /\.zip$/ ? "unzip -p $in|" : "$in") || die "Can't open $in: $!\n";
open IN, $in_cmd;

while (<IN>) {
$gff = 2 if /^##gff-version 2/;
$gff = 3 if /^##gff-version 3/;
next if /^#/ && $gff;

s/\s+$//;
# 0-chr 1-src 2-feat 3-beg 4-end 5-scor 6-dir 7-fram 8-attr
my @f = split /\t/;
if ($gff) {
# most ver 2's stick gene names in the id field
($id) = $f[8]=~ /\bID="([^"]+)"/;
# most ver 3's stick unquoted names in the name field
($id) = $f[8]=~ /\bName=([^";]+)/ if !$id && $gff == 3;
} else {
($id) = $f[8]=~ /transcript_id "([^"]+)"/;
}

next unless $id && $f[0];

if ($f[2] eq 'exon') {
die "no position at exon on line $." if ! $f[3];
# gff3 puts :\d in exons sometimes
$id =~ s/:\d+$// if $gff == 3;
push @{$exons{$id}}, \@f;
# save lowest start
$trans{$id} = \@f if !$trans{$id};
} elsif ($f[2] eq 'start_codon') {
#optional, output codon start/stop as "thick" region in bed
$sc{$id}->[0] = $f[3];
} elsif ($f[2] eq 'stop_codon') {
$sc{$id}->[1] = $f[4];
} elsif ($f[2] eq 'miRNA' ) {
$trans{$id} = \@f if !$trans{$id};
push @{$exons{$id}}, \@f;
}
}

for $id (
# sort by chr then pos
sort {
$trans{$a}->[0] eq $trans{$b}->[0] ?
$trans{$a}->[3] <=> $trans{$b}->[3] :
$trans{$a}->[0] cmp $trans{$b}->[0]
} (keys(%trans)) ) {
my ($chr, undef, undef, undef, undef, undef, $dir, undef, $attr, undef, $cds, $cde) = @{$trans{$id}};
my ($cds, $cde);
($cds, $cde) = @{$sc{$id}} if $sc{$id};

# sort by pos
my @ex = sort {
$a->[3] <=> $b->[3]
} @{$exons{$id}};

my $beg = $ex[0][3];
my $end = $ex[-1][4];

if ($dir eq '-') {
# swap
$tmp=$cds;
$cds=$cde;
$cde=$tmp;
$cds -= 2 if $cds;
$cde += 2 if $cde;
}

# not specified, just use exons
$cds = $beg if !$cds;
$cde = $end if !$cde;

# adjust start for bed
--$beg; --$cds;

my $exn = @ex; # exon count
my $exst = join ",", map {$_->[3]-$beg-1} @ex; # exon start
my $exsz = join ",", map {$_->[4]-$_->[3]+1} @ex; # exon size

my $gene_id;
my $extend = "";
if ($extended) {
($gene_id) = $attr =~ /gene_name "([^"]+)"/;
($gene_id) = $attr =~ /gene_id "([^"]+)"/ unless $gene_id;
$extend="\t$gene_id";
}
# added an extra comma to make it look exactly like ucsc's beds
print "$chr\t$beg\t$end\t$id\t0\t$dir\t$cds\t$cde\t0\t$exn\t$exsz,\t$exst,$extend\n";
}


close IN;
5 changes: 0 additions & 5 deletions modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
"git_sha": "467c202a876d26af544fa8c4b22a050a535462a7",
"installed_by": ["modules"]
},
"bedops/convert2bed": {
"branch": "master",
"git_sha": "666652151335353eef2fcd58880bcef5bc2928e1",
"installed_by": ["modules"]
},
"cat/cat": {
"branch": "master",
"git_sha": "666652151335353eef2fcd58880bcef5bc2928e1",
Expand Down
2 changes: 1 addition & 1 deletion modules/local/get_rrna_transcript/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ process GET_RRNA_TRANSCRIPTS {

script:
"""
$baseDir/bin/get_rrna_transcripts.py --gtf ${gtf} --output rrna.gtf
$baseDir/bin/get_rrna_transcripts.py ${gtf} rrna.gtf
$baseDir/bin/gtf2bed rrna.gtf > rrna.bed
Expand Down
5 changes: 0 additions & 5 deletions modules/nf-core/bedops/convert2bed/environment.yml

This file was deleted.

48 changes: 0 additions & 48 deletions modules/nf-core/bedops/convert2bed/main.nf

This file was deleted.

45 changes: 0 additions & 45 deletions modules/nf-core/bedops/convert2bed/meta.yml

This file was deleted.

59 changes: 0 additions & 59 deletions modules/nf-core/bedops/convert2bed/tests/main.nf.test

This file was deleted.

68 changes: 0 additions & 68 deletions modules/nf-core/bedops/convert2bed/tests/main.nf.test.snap

This file was deleted.

2 changes: 0 additions & 2 deletions modules/nf-core/bedops/convert2bed/tests/tags.yml

This file was deleted.

0 comments on commit f6cdcf6

Please sign in to comment.