!/usr/bin/perl # filename: Read_Bow_SNP.pl ## 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; use warnings; ## Hashes initialized my %input; my %bowtieP; my $location = 0; ## Open files # file1 - input: create window # from position open (FILE1, "Mock3_SNP.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 $name = $line[0]; my $chr = "chr$line[1]"; my $pos = $line[2]; $input{$name}[0] = $name; $input{$name}[1] = $chr; $input{$name}[2] = $pos; } close FILE1; open (OUT, "> test.txt"); ### Change if file name changes print OUT "ID\tInput chr\tInput pos\tBow ID\tBow strand\tBow chr\tBow pos\tBow pos+35\tSeq\tSNP\n"; open (FILE2, "Mock3_forSNP.bow"); #bow file while () { chomp; my @line = split /\s+/, $_; if ($line[6]==0) { my $ID = $line[0]; my $strand = $line[1]; my $chr = $line[2]; my $pos = $line[3]; my $seq = $line[4]; foreach my $name(keys %input) { if ($input{$name}[1] eq $chr) { if ($input{$name}[2] > $pos-1 && $input{$name}[2] < $pos+36) { #print OUT "$input{$name}[0]\t$input{$name}[1]\t$input{$name}[2]\t$ID\t$strand\t$chr\t$pos\t$pos+35\t$seq\n"; print OUT "$input{$name}[0]\t$input{$name}[1]\t$input{$name}[2]\t$ID\t$strand\t$chr\t$pos\t($pos+35)\t$seq\t"; if ($input{$name}[2] == $pos) { my $fSNP = substr($seq, 0, 1); print OUT "$fSNP\n"; } if ($input{$name}[2] == $pos+35) { my $fSNP = substr($seq, 35,1); print OUT "$fSNP\n"; } if ($input{$name}[2] != $pos+35 && $input{$name}[2] != $pos) { my $SNP = substr($seq, 0, $input{$name}[2]-($pos-1)); my $fSNP = substr($SNP, $input{$name}[2]-$pos); print OUT "$fSNP\n"; } } } } } } close FILE2; close OUT;