annotate bin/piPipe.pl @ 33:46d7549c1a05 draft

Uploaded
author romaingred
date Tue, 28 Nov 2017 09:08:13 -0500
parents 241aa6141cac
children 67edc34cf0ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
198009598544 Uploaded
romaingred
parents:
diff changeset
1 #!/usr/bin/perl
198009598544 Uploaded
romaingred
parents:
diff changeset
2 use strict;
198009598544 Uploaded
romaingred
parents:
diff changeset
3 use warnings;
198009598544 Uploaded
romaingred
parents:
diff changeset
4 use Getopt::Long;
198009598544 Uploaded
romaingred
parents:
diff changeset
5 use Parallel::ForkManager;
198009598544 Uploaded
romaingred
parents:
diff changeset
6 use File::Basename;
198009598544 Uploaded
romaingred
parents:
diff changeset
7 use File::Copy::Recursive qw( dircopy );
198009598544 Uploaded
romaingred
parents:
diff changeset
8 use POSIX;
198009598544 Uploaded
romaingred
parents:
diff changeset
9 use FindBin;
198009598544 Uploaded
romaingred
parents:
diff changeset
10 use lib $FindBin::Bin;
198009598544 Uploaded
romaingred
parents:
diff changeset
11 use resize qw ( size_distribution );
198009598544 Uploaded
romaingred
parents:
diff changeset
12 use subgroups qw (subgroups );
198009598544 Uploaded
romaingred
parents:
diff changeset
13 use ppp qw ( ping_pong_partners );
198009598544 Uploaded
romaingred
parents:
diff changeset
14 use Rcall qw (pie_chart bg_to_png );
198009598544 Uploaded
romaingred
parents:
diff changeset
15 use align qw ( to_build get_unique sam_count sam_count_mis sam_sorted_bam rpms_rpkm BWA_call get_fastq_seq extract_sam sam_to_bam_bg );
198009598544 Uploaded
romaingred
parents:
diff changeset
16 use html qw ( main_page details_pages menu_page ppp_page );
198009598544 Uploaded
romaingred
parents:
diff changeset
17 use File::Copy;
198009598544 Uploaded
romaingred
parents:
diff changeset
18
29
0a47c6cf912d Uploaded
romaingred
parents: 28
diff changeset
19 my ( @fastq, @fastq_n, $dir, $min, $max, $mis, $misTE, $help, $Pcheck, $mapnumf, $html_out);
0
198009598544 Uploaded
romaingred
parents:
diff changeset
20 my ( $ref, $tRNAs, $rRNAs, $snRNAs, $miRNAs, $exons, $TE );
198009598544 Uploaded
romaingred
parents:
diff changeset
21 my ( $si_min, $si_max, $pi_min, $pi_max );
198009598544 Uploaded
romaingred
parents:
diff changeset
22 my ( $build_index, $build_tRNAs, $build_rRNAs, $build_snRNAs, $build_miRNAs, $build_exons, $build_TE );
21
2bd100775c36 Uploaded
romaingred
parents: 0
diff changeset
23 my $max_procs = 8;
0
198009598544 Uploaded
romaingred
parents:
diff changeset
24
198009598544 Uploaded
romaingred
parents:
diff changeset
25 ( $build_index, $build_tRNAs, $build_rRNAs, $build_snRNAs, $build_miRNAs, $build_exons, $build_TE ) = (0,0,0,0,0,0,0);
198009598544 Uploaded
romaingred
parents:
diff changeset
26 ( $min, $max, $mis, $misTE, $si_min, $si_max, $pi_min, $pi_max, $dir ) = ( 18, 29, 0, 3, 21, 21, 23, 29 );
198009598544 Uploaded
romaingred
parents:
diff changeset
27 $Pcheck ='true';
198009598544 Uploaded
romaingred
parents:
diff changeset
28
198009598544 Uploaded
romaingred
parents:
diff changeset
29 GetOptions (
198009598544 Uploaded
romaingred
parents:
diff changeset
30 "fastq=s" => \@fastq,
198009598544 Uploaded
romaingred
parents:
diff changeset
31 "fastq_n=s" => \@fastq_n,
198009598544 Uploaded
romaingred
parents:
diff changeset
32 "dir=s" => \$dir,
198009598544 Uploaded
romaingred
parents:
diff changeset
33 "min:i" => \$min,
198009598544 Uploaded
romaingred
parents:
diff changeset
34 "max:i" => \$max,
198009598544 Uploaded
romaingred
parents:
diff changeset
35 "si_min:i" => \$si_min,
198009598544 Uploaded
romaingred
parents:
diff changeset
36 "si_max:i" => \$si_max,
198009598544 Uploaded
romaingred
parents:
diff changeset
37 "pi_min:i" => \$pi_min,
198009598544 Uploaded
romaingred
parents:
diff changeset
38 "pi_max:i" => \$pi_max,
198009598544 Uploaded
romaingred
parents:
diff changeset
39 "mis:i" => \$mis,
198009598544 Uploaded
romaingred
parents:
diff changeset
40 "misTE:i" => \$misTE,
198009598544 Uploaded
romaingred
parents:
diff changeset
41 "html:s" => \$html_out,
198009598544 Uploaded
romaingred
parents:
diff changeset
42 "PPPon:s" => \$Pcheck,
198009598544 Uploaded
romaingred
parents:
diff changeset
43 "help" => \$help,
198009598544 Uploaded
romaingred
parents:
diff changeset
44 "ref:s" => \$ref,
198009598544 Uploaded
romaingred
parents:
diff changeset
45 "tRNAs:s" => \$tRNAs,
198009598544 Uploaded
romaingred
parents:
diff changeset
46 "rRNAs:s" => \$rRNAs,
198009598544 Uploaded
romaingred
parents:
diff changeset
47 "snRNAs:s" => \$snRNAs,
198009598544 Uploaded
romaingred
parents:
diff changeset
48 "miRNAs:s" => \$miRNAs,
198009598544 Uploaded
romaingred
parents:
diff changeset
49 "exons:s" => \$exons,
198009598544 Uploaded
romaingred
parents:
diff changeset
50 "TE:s" => \$TE,
198009598544 Uploaded
romaingred
parents:
diff changeset
51 "build_index" => \$build_index,
198009598544 Uploaded
romaingred
parents:
diff changeset
52 "build_tRNAs" => \$build_tRNAs,
198009598544 Uploaded
romaingred
parents:
diff changeset
53 "build_snRNAs" => \$build_snRNAs,
198009598544 Uploaded
romaingred
parents:
diff changeset
54 "build_miRNAs" => \$build_miRNAs,
198009598544 Uploaded
romaingred
parents:
diff changeset
55 "build_exons" => \$build_exons,
198009598544 Uploaded
romaingred
parents:
diff changeset
56 "build_rRNAs" => \$build_rRNAs,
198009598544 Uploaded
romaingred
parents:
diff changeset
57 "build_TE" => \$build_TE
198009598544 Uploaded
romaingred
parents:
diff changeset
58 );
198009598544 Uploaded
romaingred
parents:
diff changeset
59
198009598544 Uploaded
romaingred
parents:
diff changeset
60 my $fq_collection = 'fastq_dir/';
198009598544 Uploaded
romaingred
parents:
diff changeset
61 mkdir $dir; mkdir $fq_collection;
198009598544 Uploaded
romaingred
parents:
diff changeset
62 $dir = $dir.'/' unless $dir =~ /\/$/;
198009598544 Uploaded
romaingred
parents:
diff changeset
63 mkdir $dir.'/css';mkdir $dir.'/js';
198009598544 Uploaded
romaingred
parents:
diff changeset
64 dircopy( $FindBin::Bin.'/css', $dir.'/css' );
198009598544 Uploaded
romaingred
parents:
diff changeset
65 dircopy( $FindBin::Bin.'/js', $dir.'/js' );
198009598544 Uploaded
romaingred
parents:
diff changeset
66
198009598544 Uploaded
romaingred
parents:
diff changeset
67 my $file = $dir.'report.txt';
198009598544 Uploaded
romaingred
parents:
diff changeset
68 open my $report, '>', $file or die "Cannot open $file $!\n";
198009598544 Uploaded
romaingred
parents:
diff changeset
69
25
f5da139a09b4 Uploaded
romaingred
parents: 23
diff changeset
70 my @toBuild = ( [$build_index, \$ref], [$build_tRNAs, \$tRNAs], [$build_rRNAs, \$rRNAs], [$build_snRNAs, \$snRNAs], [$build_miRNAs, \$miRNAs], [$build_exons, \$exons], [$build_TE, \$TE] );
27
fe5a96def00e Uploaded
romaingred
parents: 26
diff changeset
71 to_build ( \@toBuild, $report, $dir );
0
198009598544 Uploaded
romaingred
parents:
diff changeset
72
198009598544 Uploaded
romaingred
parents:
diff changeset
73 my $proc_child = ceil($max_procs / scalar(@fastq));
21
2bd100775c36 Uploaded
romaingred
parents: 0
diff changeset
74 my $proc_grand_child = ceil($proc_child/4);
0
198009598544 Uploaded
romaingred
parents:
diff changeset
75 my $pm = Parallel::ForkManager->new($max_procs);
21
2bd100775c36 Uploaded
romaingred
parents: 0
diff changeset
76 my $pm2 = Parallel::ForkManager->new($proc_grand_child);
0
198009598544 Uploaded
romaingred
parents:
diff changeset
77
198009598544 Uploaded
romaingred
parents:
diff changeset
78 $pm->run_on_finish( sub {
198009598544 Uploaded
romaingred
parents:
diff changeset
79 my ($pid, $exit_code, $ident) = @_;
198009598544 Uploaded
romaingred
parents:
diff changeset
80 print $report "Fastq fork $ident just finished ".
198009598544 Uploaded
romaingred
parents:
diff changeset
81 "with PID $pid and exit code: $exit_code\n";
198009598544 Uploaded
romaingred
parents:
diff changeset
82 die "Something went wrong!\n" if $exit_code != 0;
198009598544 Uploaded
romaingred
parents:
diff changeset
83 });
198009598544 Uploaded
romaingred
parents:
diff changeset
84 $pm->run_on_start( sub {
198009598544 Uploaded
romaingred
parents:
diff changeset
85 my ($pid,$ident)=@_;
198009598544 Uploaded
romaingred
parents:
diff changeset
86 print $report "Fastq fork : $ident started, pid: $pid\n";
198009598544 Uploaded
romaingred
parents:
diff changeset
87 });
21
2bd100775c36 Uploaded
romaingred
parents: 0
diff changeset
88 $pm2->run_on_finish( sub {
0
198009598544 Uploaded
romaingred
parents:
diff changeset
89 my ($pid, $exit_code, $ident) = @_;
198009598544 Uploaded
romaingred
parents:
diff changeset
90 print $report "** Subgroup fork $ident just finished ".
198009598544 Uploaded
romaingred
parents:
diff changeset
91 "with PID $pid and exit code: $exit_code\n";
198009598544 Uploaded
romaingred
parents:
diff changeset
92 die "Something went wrong!\n" if $exit_code != 0;
198009598544 Uploaded
romaingred
parents:
diff changeset
93 });
21
2bd100775c36 Uploaded
romaingred
parents: 0
diff changeset
94 $pm2->run_on_start( sub {
0
198009598544 Uploaded
romaingred
parents:
diff changeset
95 my ($pid,$ident)=@_;
198009598544 Uploaded
romaingred
parents:
diff changeset
96 print $report "** Subgroup fork $ident started, pid: $pid\n";
198009598544 Uploaded
romaingred
parents:
diff changeset
97 });
198009598544 Uploaded
romaingred
parents:
diff changeset
98
198009598544 Uploaded
romaingred
parents:
diff changeset
99
198009598544 Uploaded
romaingred
parents:
diff changeset
100 foreach my $child ( 0 .. $#fastq )
198009598544 Uploaded
romaingred
parents:
diff changeset
101 {
198009598544 Uploaded
romaingred
parents:
diff changeset
102 my @suffix = ('.fastq', '.fastq.gz,', '.fq', '.fq.gz', 'ref', '.dat', '.fa','.fas','.fasta', '.txt');
198009598544 Uploaded
romaingred
parents:
diff changeset
103 my ( $name, $path, $suffix ) = fileparse( $fastq[$child], @suffix );
198009598544 Uploaded
romaingred
parents:
diff changeset
104 my ( $ref_name, $ref_path, $ref_suffix ) = fileparse( $ref, @suffix );
198009598544 Uploaded
romaingred
parents:
diff changeset
105 my ( $TE_name, $TE_path, $TE_suffix ) = fileparse( $TE, @suffix );
198009598544 Uploaded
romaingred
parents:
diff changeset
106 my ( $ex_name, $ex_path, $ex_suffix ) = fileparse( $exons,@suffix );
198009598544 Uploaded
romaingred
parents:
diff changeset
107
198009598544 Uploaded
romaingred
parents:
diff changeset
108 $pm->start($fastq[$child]) and next;
198009598544 Uploaded
romaingred
parents:
diff changeset
109
198009598544 Uploaded
romaingred
parents:
diff changeset
110 my $dir_fq = $dir.$name.'/';
198009598544 Uploaded
romaingred
parents:
diff changeset
111 mkdir $dir_fq;
198009598544 Uploaded
romaingred
parents:
diff changeset
112
198009598544 Uploaded
romaingred
parents:
diff changeset
113 my $gen_dir = $dir_fq.'genome/';
198009598544 Uploaded
romaingred
parents:
diff changeset
114 mkdir $gen_dir;
198009598544 Uploaded
romaingred
parents:
diff changeset
115
198009598544 Uploaded
romaingred
parents:
diff changeset
116 my $size_dir = $dir_fq.'size/';
198009598544 Uploaded
romaingred
parents:
diff changeset
117 mkdir $size_dir;
198009598544 Uploaded
romaingred
parents:
diff changeset
118
198009598544 Uploaded
romaingred
parents:
diff changeset
119 my $fastq_resized = $dir_fq.$name.'_'.$min.'-'.$max.'.fastq';
198009598544 Uploaded
romaingred
parents:
diff changeset
120 size_distribution ( $fastq[$child], $fastq_resized, $size_dir, $min, $max );
198009598544 Uploaded
romaingred
parents:
diff changeset
121
198009598544 Uploaded
romaingred
parents:
diff changeset
122 my $sam_genome = $gen_dir.$name.'_'.$min.'-'.$max.'_'.$ref_name.'.sam';
198009598544 Uploaded
romaingred
parents:
diff changeset
123 my $sam_genome_unique = $gen_dir.$name.'_'.$min.'-'.$max.'_'.$ref_name.'_unique.sam';
198009598544 Uploaded
romaingred
parents:
diff changeset
124 my $fastq_prefix = $gen_dir.$name.'_'.$min.'-'.$max.'_'.$ref_name;
198009598544 Uploaded
romaingred
parents:
diff changeset
125
198009598544 Uploaded
romaingred
parents:
diff changeset
126 BWA_call ( $ref, $fastq_resized, $sam_genome, $mis, $proc_child, $report );
198009598544 Uploaded
romaingred
parents:
diff changeset
127 my ( $fai_ref_hashP, $ma, $ma_uni ) = get_unique ( $sam_genome, $sam_genome_unique, $gen_dir, 1, $report );
198009598544 Uploaded
romaingred
parents:
diff changeset
128
198009598544 Uploaded
romaingred
parents:
diff changeset
129 my $scale = 1000000 / $ma;
198009598544 Uploaded
romaingred
parents:
diff changeset
130 sam_to_bam_bg ( $sam_genome_unique, $scale, $proc_child );
198009598544 Uploaded
romaingred
parents:
diff changeset
131 sam_to_bam_bg ( $sam_genome, $scale, $proc_child );
198009598544 Uploaded
romaingred
parents:
diff changeset
132
198009598544 Uploaded
romaingred
parents:
diff changeset
133 my $Gviz_dir = $gen_dir.'Gviz/';
198009598544 Uploaded
romaingred
parents:
diff changeset
134 my $fai_file = $gen_dir.'fai';
198009598544 Uploaded
romaingred
parents:
diff changeset
135 mkdir $Gviz_dir;
198009598544 Uploaded
romaingred
parents:
diff changeset
136 my $Gviz_dir_rand = $Gviz_dir.'rand/';
198009598544 Uploaded
romaingred
parents:
diff changeset
137 mkdir $Gviz_dir_rand;
198009598544 Uploaded
romaingred
parents:
diff changeset
138 my $Gviz_dir_uni = $Gviz_dir.'unique/';
198009598544 Uploaded
romaingred
parents:
diff changeset
139 mkdir $Gviz_dir_uni;
198009598544 Uploaded
romaingred
parents:
diff changeset
140
198009598544 Uploaded
romaingred
parents:
diff changeset
141 open my $gfai, '>', $fai_file;
198009598544 Uploaded
romaingred
parents:
diff changeset
142 foreach my $k ( sort keys %{$fai_ref_hashP} )
198009598544 Uploaded
romaingred
parents:
diff changeset
143 {
198009598544 Uploaded
romaingred
parents:
diff changeset
144 print $gfai "$k\t$fai_ref_hashP->{$k}\n";
198009598544 Uploaded
romaingred
parents:
diff changeset
145 }
198009598544 Uploaded
romaingred
parents:
diff changeset
146 close $gfai;
198009598544 Uploaded
romaingred
parents:
diff changeset
147 bg_to_png ( $fai_file, $fastq_prefix.'_unique_plus.bedgraph', $fastq_prefix.'_unique_minus.bedgraph', $Gviz_dir_uni, 'Mb' );
198009598544 Uploaded
romaingred
parents:
diff changeset
148 bg_to_png ( $fai_file, $fastq_prefix.'_plus.bedgraph', $fastq_prefix.'_minus.bedgraph', $Gviz_dir_rand, 'Mb' );
198009598544 Uploaded
romaingred
parents:
diff changeset
149
198009598544 Uploaded
romaingred
parents:
diff changeset
150 my $group_dir = $dir_fq.'subgroups/';
198009598544 Uploaded
romaingred
parents:
diff changeset
151 my $fastq_uni = $gen_dir.'unique.fastq';
198009598544 Uploaded
romaingred
parents:
diff changeset
152 my $fastq_all = $gen_dir.'all.fastq';
198009598544 Uploaded
romaingred
parents:
diff changeset
153 my ($bo, $mi, $pi) = subgroups ( $fastq_all, $group_dir, $mis, $misTE, $proc_child, $tRNAs, $rRNAs, $snRNAs, $miRNAs, $exons, $TE, $si_min, $si_max, $pi_min, $pi_max, $report);
198009598544 Uploaded
romaingred
parents:
diff changeset
154
198009598544 Uploaded
romaingred
parents:
diff changeset
155 pie_chart($group_dir);
198009598544 Uploaded
romaingred
parents:
diff changeset
156
198009598544 Uploaded
romaingred
parents:
diff changeset
157 open (my $dupnum, $gen_dir.'dup_mapnum.txt') || die "cannot open dup_mapnum.txt $!";
198009598544 Uploaded
romaingred
parents:
diff changeset
158 my %dupnum_genome;
198009598544 Uploaded
romaingred
parents:
diff changeset
159 my $header = <$dupnum>;
198009598544 Uploaded
romaingred
parents:
diff changeset
160 while (<$dupnum>)
198009598544 Uploaded
romaingred
parents:
diff changeset
161 {
198009598544 Uploaded
romaingred
parents:
diff changeset
162 chomp $_;
198009598544 Uploaded
romaingred
parents:
diff changeset
163 my @dupline = split /\t/, $_;
198009598544 Uploaded
romaingred
parents:
diff changeset
164 $dupnum_genome{$dupline[0]} = [$dupline[1], $dupline[2]];
198009598544 Uploaded
romaingred
parents:
diff changeset
165 }
198009598544 Uploaded
romaingred
parents:
diff changeset
166 close $dupnum;
198009598544 Uploaded
romaingred
parents:
diff changeset
167
198009598544 Uploaded
romaingred
parents:
diff changeset
168 my $mi_sam = $group_dir.'miRNAs.sam';
198009598544 Uploaded
romaingred
parents:
diff changeset
169 mkdir $group_dir.'miRNAs/';
198009598544 Uploaded
romaingred
parents:
diff changeset
170 my $mi_count_file = $group_dir.'miRNAs/miRNAs_reads_counts.txt';
198009598544 Uploaded
romaingred
parents:
diff changeset
171 my ( $mi_count, $mi_ref_size ) = sam_count ( $mi_sam );
198009598544 Uploaded
romaingred
parents:
diff changeset
172
198009598544 Uploaded
romaingred
parents:
diff changeset
173 rpms_rpkm( $mi_count, $mi_ref_size, $ma, $mi_count_file, $pi, $mi, $bo );
198009598544 Uploaded
romaingred
parents:
diff changeset
174
198009598544 Uploaded
romaingred
parents:
diff changeset
175 my ( $sam_exons, $sam_TEs ) = ( $group_dir.'exons.sam', $group_dir.'TEs.sam' );
198009598544 Uploaded
romaingred
parents:
diff changeset
176 my @types = ($group_dir.'bonafide_reads.fastq', $group_dir.'miRNAs.fastq', $group_dir.'siRNAs.fastq', $group_dir.'piRNAs.fastq' );
198009598544 Uploaded
romaingred
parents:
diff changeset
177 my @types_names = ('bonafide_reads', 'miRNAs', 'siRNAs', 'piRNAs');
198009598544 Uploaded
romaingred
parents:
diff changeset
178 foreach my $grand_child ( 0 .. $#types )
198009598544 Uploaded
romaingred
parents:
diff changeset
179 {
198009598544 Uploaded
romaingred
parents:
diff changeset
180 my $type_dir = $group_dir.$types_names[$grand_child].'/';
198009598544 Uploaded
romaingred
parents:
diff changeset
181 my $type_prefix = $types_names[$grand_child].'-';
198009598544 Uploaded
romaingred
parents:
diff changeset
182 mkdir $type_dir;
21
2bd100775c36 Uploaded
romaingred
parents: 0
diff changeset
183 $pm2->start($types[$grand_child]) and next;
0
198009598544 Uploaded
romaingred
parents:
diff changeset
184 my ( $type_sam_genome, $type_sam_TEs, $type_sam_exons ) = ( $type_dir.$type_prefix.'genome.sam', $type_dir.$type_prefix.'TEs.sam', $type_dir.$type_prefix.'exons.sam' );
198009598544 Uploaded
romaingred
parents:
diff changeset
185 my ( $type_sam_uni_genome, $type_sam_uni_TEs, $type_sam_uni_exons ) = ( $type_dir.$type_prefix.'genome_unique.sam', $type_dir.$type_prefix.'TEs_unique.sam', $type_dir.$type_prefix.'exons_unique.sam' );
198009598544 Uploaded
romaingred
parents:
diff changeset
186 my ( $type_uni_genome_fastq, $type_uni_TEs_fastq, $type_uni_exons_fastq ) = ( $fq_collection.$type_prefix.'genome_uni.fastq', $fq_collection.$type_prefix.'TEs_uni.fastq', $fq_collection.$type_prefix.'exons_uni.fastq');
198009598544 Uploaded
romaingred
parents:
diff changeset
187 my ( $type_genome_fastq, $type_TEs_fastq, $type_exons_fastq ) = ( $fq_collection.$type_prefix.'genome.fastq', $fq_collection.$type_prefix.'TEs.fastq', $fq_collection.$type_prefix.'exons.fastq');
198009598544 Uploaded
romaingred
parents:
diff changeset
188 my $type_sequence_hashP = get_fastq_seq ( $types[$grand_child] );
198009598544 Uploaded
romaingred
parents:
diff changeset
189
198009598544 Uploaded
romaingred
parents:
diff changeset
190 if ( $grand_child == 1 )
198009598544 Uploaded
romaingred
parents:
diff changeset
191 {
198009598544 Uploaded
romaingred
parents:
diff changeset
192 BWA_call ( $TE, $types[$grand_child], $type_sam_TEs, $misTE, $proc_child, $report );
198009598544 Uploaded
romaingred
parents:
diff changeset
193 BWA_call ( $exons, $types[$grand_child], $type_sam_exons, $mis, $proc_child, $report );
198009598544 Uploaded
romaingred
parents:
diff changeset
194 BWA_call ( $ref, $types[$grand_child], $type_sam_genome, $mis, $proc_child, $report );
198009598544 Uploaded
romaingred
parents:
diff changeset
195 extract_sam ( undef, $type_sam_TEs, $type_sam_TEs, $type_sam_uni_TEs, $type_uni_TEs_fastq, $type_uni_TEs_fastq );
198009598544 Uploaded
romaingred
parents:
diff changeset
196 extract_sam ( undef, $type_sam_exons, $type_sam_exons, $type_sam_uni_exons, $type_exons_fastq, $type_uni_exons_fastq );
198009598544 Uploaded
romaingred
parents:
diff changeset
197 extract_sam ( undef, $type_sam_genome, $type_sam_genome, $type_sam_uni_genome, $type_genome_fastq, $type_uni_genome_fastq );
198009598544 Uploaded
romaingred
parents:
diff changeset
198 }
198009598544 Uploaded
romaingred
parents:
diff changeset
199 else
198009598544 Uploaded
romaingred
parents:
diff changeset
200 {
198009598544 Uploaded
romaingred
parents:
diff changeset
201 extract_sam ( $type_sequence_hashP, $sam_TEs, $type_sam_TEs, $type_sam_uni_TEs, $type_TEs_fastq, $type_uni_TEs_fastq );
198009598544 Uploaded
romaingred
parents:
diff changeset
202 extract_sam ( $type_sequence_hashP, $sam_exons, $type_sam_exons, $type_sam_uni_exons, $type_exons_fastq, $type_uni_exons_fastq );
198009598544 Uploaded
romaingred
parents:
diff changeset
203 extract_sam ( $type_sequence_hashP, $sam_genome, $type_sam_genome, $type_sam_uni_genome, $type_genome_fastq, $type_uni_genome_fastq );
198009598544 Uploaded
romaingred
parents:
diff changeset
204 }
198009598544 Uploaded
romaingred
parents:
diff changeset
205
198009598544 Uploaded
romaingred
parents:
diff changeset
206 my $ex_count_file = $type_dir.'exons_reads_counts.txt';
198009598544 Uploaded
romaingred
parents:
diff changeset
207 my ( $ex_count, $ex_ref_size ) = sam_count ( $type_sam_exons );
198009598544 Uploaded
romaingred
parents:
diff changeset
208 rpms_rpkm( $ex_count, $ex_ref_size, $ma, $ex_count_file, $pi, $mi, $bo );
198009598544 Uploaded
romaingred
parents:
diff changeset
209
198009598544 Uploaded
romaingred
parents:
diff changeset
210 my ( $TEs_count, $TEs_ref_size, $TEs_count_NoM, $TEs_count_M ) = sam_count_mis ( $type_sam_TEs );
198009598544 Uploaded
romaingred
parents:
diff changeset
211 my $TEs_count_file = $type_dir.$type_prefix.'TEs_reads_counts.txt';
198009598544 Uploaded
romaingred
parents:
diff changeset
212 my $TEs_count_file_M = $type_dir.$type_prefix.'TEs_reads_counts_mismatches.txt';
198009598544 Uploaded
romaingred
parents:
diff changeset
213 my $TEs_count_file_noM = $type_dir.$type_prefix.'TEs_reads_counts_nomismatches.txt';
198009598544 Uploaded
romaingred
parents:
diff changeset
214 rpms_rpkm( $TEs_count, $TEs_ref_size, $ma, $TEs_count_file, $pi, $mi, $bo );
29
0a47c6cf912d Uploaded
romaingred
parents: 28
diff changeset
215 rpms_rpkm( $TEs_count_NoM, $TEs_ref_size, $ma, $TEs_count_file_noM, $pi, $mi, $bo );
0a47c6cf912d Uploaded
romaingred
parents: 28
diff changeset
216 rpms_rpkm( $TEs_count_M, $TEs_ref_size, $ma, $TEs_count_file_M, $pi, $mi, $bo );
0
198009598544 Uploaded
romaingred
parents:
diff changeset
217
198009598544 Uploaded
romaingred
parents:
diff changeset
218 sam_to_bam_bg ( $type_sam_TEs, $scale, $grand_child );
198009598544 Uploaded
romaingred
parents:
diff changeset
219 sam_sorted_bam ( $type_sam_exons, $grand_child ); sam_sorted_bam ( $type_sam_uni_exons, $grand_child );
198009598544 Uploaded
romaingred
parents:
diff changeset
220 sam_sorted_bam ( $type_sam_uni_TEs, $grand_child );
198009598544 Uploaded
romaingred
parents:
diff changeset
221
198009598544 Uploaded
romaingred
parents:
diff changeset
222 my $Gviz_TEs = $type_dir.'Gviz_TEs/';
198009598544 Uploaded
romaingred
parents:
diff changeset
223 mkdir $Gviz_TEs;
198009598544 Uploaded
romaingred
parents:
diff changeset
224 bg_to_png ( $group_dir.'TEs.fai', $type_dir.$type_prefix.'TEs_plus.bedgraph', $type_dir.$type_prefix.'TEs_minus.bedgraph', $Gviz_TEs, 'Kb' );
198009598544 Uploaded
romaingred
parents:
diff changeset
225
198009598544 Uploaded
romaingred
parents:
diff changeset
226 my $Gviz_genome= $type_dir.'Gviz_genome/';
198009598544 Uploaded
romaingred
parents:
diff changeset
227 my $Gviz_genome_rand = $Gviz_genome.'rand/';
198009598544 Uploaded
romaingred
parents:
diff changeset
228 my $Gviz_genome_uni = $Gviz_genome.'unique/';
198009598544 Uploaded
romaingred
parents:
diff changeset
229 mkdir $Gviz_genome; mkdir $Gviz_genome_uni; mkdir $Gviz_genome_rand;
198009598544 Uploaded
romaingred
parents:
diff changeset
230
198009598544 Uploaded
romaingred
parents:
diff changeset
231 sam_to_bam_bg ( $type_sam_genome, $scale, $grand_child );
198009598544 Uploaded
romaingred
parents:
diff changeset
232 sam_to_bam_bg ( $type_sam_uni_genome, $scale, $grand_child );
198009598544 Uploaded
romaingred
parents:
diff changeset
233
198009598544 Uploaded
romaingred
parents:
diff changeset
234 bg_to_png ( $fai_file, $type_dir.$type_prefix.'genome_unique_plus.bedgraph', $type_dir.$type_prefix.'genome_unique_minus.bedgraph', $Gviz_genome_uni, 'Mb' );
198009598544 Uploaded
romaingred
parents:
diff changeset
235 bg_to_png ( $fai_file, $type_dir.$type_prefix.'genome_plus.bedgraph', $type_dir.$type_prefix.'genome_minus.bedgraph', $Gviz_genome_rand, 'Mb' );
198009598544 Uploaded
romaingred
parents:
diff changeset
236
198009598544 Uploaded
romaingred
parents:
diff changeset
237 #HTML Details
198009598544 Uploaded
romaingred
parents:
diff changeset
238 my $prefix_details_pages = $dir.$fastq_n[$child].'-'.$types_names[$grand_child];
29
0a47c6cf912d Uploaded
romaingred
parents: 28
diff changeset
239 details_pages ( $type_dir, $prefix_details_pages, \@fastq_n, $fastq_n[$child], $misTE, $dir, $Pcheck );
0
198009598544 Uploaded
romaingred
parents:
diff changeset
240
21
2bd100775c36 Uploaded
romaingred
parents: 0
diff changeset
241 $pm2->finish();
0
198009598544 Uploaded
romaingred
parents:
diff changeset
242 }
21
2bd100775c36 Uploaded
romaingred
parents: 0
diff changeset
243 $pm2->wait_all_children;
0
198009598544 Uploaded
romaingred
parents:
diff changeset
244
198009598544 Uploaded
romaingred
parents:
diff changeset
245 if ( $Pcheck eq 'true' )
198009598544 Uploaded
romaingred
parents:
diff changeset
246 {
198009598544 Uploaded
romaingred
parents:
diff changeset
247 my $ppp = $group_dir.'PPPartners/'; mkdir $ppp;
31
241aa6141cac Uploaded
romaingred
parents: 29
diff changeset
248 print $report "ping_pong_partners $group_dir/piRNAs/TEs.sam $ppp\n";
241aa6141cac Uploaded
romaingred
parents: 29
diff changeset
249 ping_pong_partners ( $group_dir.'TEs.fai', $group_dir.'piRNAs/piRNAs-TEs_sorted.bam', $ppp, $pi_min );
33
46d7549c1a05 Uploaded
romaingred
parents: 31
diff changeset
250 my $ppp_page = $dir.$fastq_n[$child].'-piRNAs-PPP.html';
0
198009598544 Uploaded
romaingred
parents:
diff changeset
251 ppp_page ( $group_dir, $ppp_page, \@fastq_n, $fastq_n[$child], $ppp, $dir );
198009598544 Uploaded
romaingred
parents:
diff changeset
252 }
198009598544 Uploaded
romaingred
parents:
diff changeset
253
198009598544 Uploaded
romaingred
parents:
diff changeset
254 #HTML Main Webpage
198009598544 Uploaded
romaingred
parents:
diff changeset
255 my $index_page = $dir.$fastq_n[$child].'.html';
198009598544 Uploaded
romaingred
parents:
diff changeset
256 main_page ( $gen_dir, $index_page, \@fastq_n, $fastq_n[$child], $ma, $ma_uni, $dir );
198009598544 Uploaded
romaingred
parents:
diff changeset
257 copy ($index_page, $html_out) if $child == 0;
198009598544 Uploaded
romaingred
parents:
diff changeset
258 #HTML Menu
198009598544 Uploaded
romaingred
parents:
diff changeset
259 my $menu_page = $dir.$fastq_n[$child].'-sub.html';
198009598544 Uploaded
romaingred
parents:
diff changeset
260 menu_page ( $group_dir, $menu_page, \@fastq_n, $fastq_n[$child], $min, $max, $si_min, $si_max, $pi_min, $pi_max, $dir );
23
7dd78ad2875f Uploaded
romaingred
parents: 21
diff changeset
261 unlink glob "$group_dir*.sam"; unlink glob "$group_dir*.fastq";
21
2bd100775c36 Uploaded
romaingred
parents: 0
diff changeset
262 $pm->finish(); # pass an exit code to finish
0
198009598544 Uploaded
romaingred
parents:
diff changeset
263 }
198009598544 Uploaded
romaingred
parents:
diff changeset
264 $pm->wait_all_children;
28
aea6ed0da85b Uploaded
romaingred
parents: 27
diff changeset
265 unlink glob $dir."dataset_*symlink.fa*";
0
198009598544 Uploaded
romaingred
parents:
diff changeset
266 print $report "Job done!\n";
198009598544 Uploaded
romaingred
parents:
diff changeset
267 close $report;