annotate convert_bowtie_to_blast.pl @ 0:87fe81de0931 draft default tip

Uploaded
author bigrna
date Sun, 04 Jan 2015 02:47:25 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
1 #!/usr/bin/perl
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
2
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
3
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
4 use warnings;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
5 use strict;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
6 use Getopt::Std;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
7
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
8 ######################################### USAGE ################################
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
9
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
10 my $usage=
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
11 "$0 file_bowtie_result file_solexa_seq file_chromosome
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
12
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
13 This is a converter which changes Bowtie output into Blast format.
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
14 The input includes three files: a Bowtie result file (default Bowtie
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
15 output file), a fasta file consisting of small Reads and a chromosome
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
16 fasta file. It outputs the alignments in blast_parsed format.
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
17
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
18 file_bowtie_result likes:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
19
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
20 AtFlower100010_x2 + MIR319c 508 AAGGAGATTCTTTCAGTCCAG IIIIIIIIIIIIIIIIIIIII 0
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
21 AtFlower1000188_x1 + MIR2933a 421 TCGGAGAGGAAATTCGTCGGCG IIIIIIIIIIIIIIIIIIIIII 0
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
22
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
23 file_solexa_seq likes:
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
24
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
25 >AtFlower100010_x2
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
26 AAGGAGATTCTTTCAGTCCAG
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
27
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
28 file_chromosome contains chromosome seq in fasta format
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
29
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
30 ";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
31
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
32
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
33 ####################################### INPUT FILES ############################
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
34
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
35 my $file_bowtie_result=shift or die $usage;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
36 my $file_short_seq=shift or die $usage;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
37 my $file_chromosome_seq=shift or die $usage;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
38
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
39
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
40 ##################################### GLOBAL VARIBALES #########################
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
41
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
42 my %short_seq_length=();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
43 my %chromosome_length=();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
44
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
45
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
46 ######################################### MAIN #################################
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
47
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
48 #get the short sequence id and its length
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
49 sequence_length($file_short_seq,\%short_seq_length);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
50
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
51 #get the chromosome sequence id and its length
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
52 sequence_length($file_chromosome_seq,\%chromosome_length);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
53
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
54 #convert bowtie result format to blast format;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
55 change_format($file_bowtie_result);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
56
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
57 exit;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
58
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
59
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
60 ##################################### SUBROUTINES ##############################
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
61
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
62 sub sequence_length{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
63 my ($file,$hash) = @_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
64 my ($id, $desc, $sequence, $seq_length) = ();
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
65
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
66 open (FASTA, "<$file") or die "can not open $$file\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
67 while (<FASTA>)
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
68 {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
69 chomp;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
70 if (/^>(\S+)(.*)/)
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
71 {
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
72 $id = $1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
73 $desc = $2;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
74 $sequence = "";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
75 while (<FASTA>){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
76 chomp;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
77 if (/^>(\S+)(.*)/){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
78 $$hash{$id} = length $sequence;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
79 $id = $1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
80 $desc = $2;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
81 $sequence = "";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
82 next;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
83 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
84 $sequence .= $_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
85 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
86 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
87 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
88 $seq_length=length($sequence);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
89 $$hash{$id} = $seq_length;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
90 close FASTA;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
91 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
92
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
93
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
94
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
95
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
96
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
97 sub change_format{
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
98 #Change Bowtie format into blast format
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
99 my $file=shift @_;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
100 open(FILE,"<$file")||die"can not open the bowtie result file:$!\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
101 #open(BLASTOUT,">blastout")||die"can not create the blastout file:$!\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
102
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
103 while(<FILE>){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
104 chomp;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
105 my @tmp=split("\t",$_);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
106 #Clean the reads ID
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
107 my @tmp1=split(" ",$tmp[0]);
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
108 print "$tmp1[0]"."\t"."$short_seq_length{$tmp1[0]}"."\t"."1".'..'."$short_seq_length{$tmp1[0]}"."\t"."$tmp[2]"."\t"."$chromosome_length{$tmp[2]}"."\t";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
109 if($tmp[1] eq "+"){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
110 my $seq_end=$tmp[3] + $short_seq_length{$tmp1[0]};
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
111 my $seq_bg=$tmp[3] + 1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
112 print "$seq_bg".'..'."$seq_end"."\t"."1e-04"."\t"."1.00"."\t"."42.1"."\t"."Plus / Plus"."\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
113 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
114 if($tmp[1] eq "-"){
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
115 my $seq_end=$chromosome_length{$tmp[2]} - $tmp[3];
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
116 my $seq_bg=$seq_end - $short_seq_length{$tmp1[0]} + 1;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
117 print "$seq_bg".'..'."$seq_end"."\t"."1e-04"."\t"."1.00"."\t"."42.1"."\t"."Plus / Minus"."\n";
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
118 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
119 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
120
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
121 # close BLASTOUT;
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
122
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
123 }
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
124
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
125
87fe81de0931 Uploaded
bigrna
parents:
diff changeset
126