## Script description: This program takes input and match the chromosome location from Bowtie parser file, # then adds the read # to the window (also including neighboring windows) ## Perl interpreter command # use warnings; use strict; ## Hashes initialized my %input; my %bowtieP; ## Open files # file1 - input: create window # from position #my $file1 = shift; # Input (chr # and position - base pair) open (FILE1, "/data/GAII/prostate_cells/SNP/Prostate_SNP_filtered.txt"); my $head = ; # If there is a header in the input #1, include this code while () { chomp; my $input_orig = $_; my @line = split /\s+/, $_; my $chr = $line[1]; my $w = (int($line[2]/100))*100; # Window # created my $w1 = $w-100; my $w2 = $w+100; my $pos = "chr$chr\_$w"; # Get new variable chr_win for input $input{$pos}[0] = $input_orig; $input{$pos}[1] = $pos; $input{$pos}[2] = 0; # Read value initialized as 0 $input{$pos}[3] = $chr; $input{$pos}[4] = $w; $input{$pos}[5] = "chr$chr\_$w1"; $input{$pos}[6] = "chr$chr\_$w2"; $input{$pos}[7] = 0; # Read value for win-100 $input{$pos}[8] = 0; # Read value for win+100 } close FILE1; # file2 - bowtie parser output #my $file2 = shift; # Bowtie Parser Input file (chr #, window #, and read value) open (FILE2, "/data/GAII/prostate_cells/DU145v2_Bow_Per100.txt"); while () { chomp; my @line = split /\s+/, $_; my $chr = $line[0]; my $w = $line[1]; my $read = $line[3]; my $pos = "$chr\_$w"; # Get new variable chr_win for bowtie parser $bowtieP{$pos}[0] = $pos; $bowtieP{$pos}[1] = $read; } close FILE2; open (OUT, "> test.txt"); ### Change if file name changes print OUT "Name\tChr\tPosition\tGenTrain Score\tPrEC\tPrEC alleles\tRWPE\tRWPE alleles\tLNCaP\tLNCaP alleles\tDU145\tDU145 alleles\tchr_win\tread\tchr_win-100\tread-100\tchr_win+100\tread+100\ttotal\n"; foreach my $pos (keys %input) { if (exists $bowtieP{$input{$pos}[1]}[0]) { $input{$pos}[2]=$bowtieP{$pos}[1]; # Change read value from input (initialized as 0) to the read value from bowtie parser data } if (exists $bowtieP{$input{$pos}[5]}[1]) { $input{$pos}[7] = $bowtieP{$input{$pos}[5]}[1]; # Change read value from input (initialized as 0) to the read value from bowtie parser data } if (exists $bowtieP{$input{$pos}[6]}[1]) { $input{$pos}[8] = $bowtieP{$input{$pos}[6]}[1]; # Change read value from input (initialized as 0) to the read value from bowtie parser data } my $total = $input{$pos}[2] + $input{$pos}[7] + $input{$pos}[8]; print OUT "$input{$pos}[0]\t$input{$pos}[1]\t$input{$pos}[2]\t$input{$pos}[5]\t$input{$pos}[7]\t$input{$pos}[6]\t$input{$pos}[8]\t$total\n"; } close OUT; exit;