1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#!/usr/bin/env perl
use strict;
use warnings;
use lib ("/usr/lib/trinityrnaseq/PerlLib");
use Process_cmd;
use Getopt::Long qw(:config no_ignore_case bundling pass_through);
use Pipeliner;
use File::Basename;
my $CPU = 2;
my $usage = <<__EOUSAGE;
############################################################
#
# Required:
#
# --genome <string> target genome.fasta file
#
# --samples_file <string> Trinity samples file
#
# Optional:
#
# --gtf <string> annotation in gtf format
#
# --CPU <int> multithreading (default: $CPU)
#
# --nameSorted sorts bam by read name
#
###########################################################
__EOUSAGE
;
my $help_flag;
my $genome_fa;
my $annotation_gtf;
my $samples_file;
my $nameSorted;
&GetOptions ( 'h' => \$help_flag,
'genome=s' => \$genome_fa,
'gtf=s' => \$annotation_gtf,
'samples_file=s' => \$samples_file,
'CPU=i' => \$CPU,
'nameSorted' => \$nameSorted,
);
if ($help_flag) { die $usage; }
unless ($genome_fa && $samples_file) {
die $usage;
}
$genome_fa = &Pipeliner::ensure_full_path($genome_fa);
$samples_file = &Pipeliner::ensure_full_path($samples_file);
$annotation_gtf = &Pipeliner::ensure_full_path($annotation_gtf) if $annotation_gtf;
main: {
my @read_sets = &parse_samples_file($samples_file);
## align reads to the mini-genome using hisat2
###########################
# first, build genome index
my $pipeliner = new Pipeliner(-verbose => 1);
if ($annotation_gtf) {
$pipeliner->add_commands(new Command("hisat2_extract_splice_sites.py $annotation_gtf > $annotation_gtf.ss",
"$annotation_gtf.ss.ok"));
$pipeliner->add_commands(new Command("hisat2_extract_exons.py $annotation_gtf > $annotation_gtf.exons",
"$annotation_gtf.exons.ok"));
$pipeliner->add_commands(new Command("hisat2-build --exon $annotation_gtf.exons --ss $annotation_gtf.ss -p $CPU $genome_fa $genome_fa",
"$genome_fa.hisat2.build.ok"));
$pipeliner->run();
}
else {
$pipeliner->add_commands(new Command("hisat2-build -p $CPU $genome_fa $genome_fa",
"$genome_fa.hisat2.nogtf.build.ok"));
$pipeliner->run();
}
#####################
## now run alignments
my $aln_checkpoints_dir = "hisat2_aln_chkpts." . basename($genome_fa);
unless (-d $aln_checkpoints_dir) {
mkdir($aln_checkpoints_dir) or die "Error, cannot mkdir $aln_checkpoints_dir";
}
my $sorted_opt = "";
my $sorted_token = "c";
if ($nameSorted) {
$sorted_opt = "-n";
$sorted_token = "n";
}
foreach my $read_set_aref (@read_sets) {
my ($sample_id, $left_fq, $right_fq) = @$read_set_aref;
my $bamfile = "$sample_id.${sorted_token}Sorted.hisat2." . basename($genome_fa) . ".bam";
$pipeliner->add_commands(new Command("bash -c \"set -eof pipefail; hisat2 --dta -x $genome_fa -p $CPU -1 $left_fq -2 $right_fq | samtools view -Sb -F 4 | samtools sort $sorted_opt -o $bamfile \" ",
"$aln_checkpoints_dir/$bamfile.ok"));
}
$pipeliner->run();
exit(0);
}
####
sub parse_samples_file {
my ($samples_file) = @_;
my @samples;
open(my $fh, $samples_file) or die "Error, cannot open file $samples_file";
while (<$fh>) {
chomp;
my @x = split(/\t/);
my ($cond, $rep, $fq_a, $fq_b) = @x;
$fq_a = &Pipeliner::ensure_full_path($fq_a);
$fq_b = &Pipeliner::ensure_full_path($fq_b) if $fq_b;
push (@samples, [$rep, $fq_a, $fq_b]);
}
close $fh;
return (@samples);
}
|