annotate convert_bowtie_to_blast.pl @ 7:6aa0e8d63b17 draft

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