0
|
1 #This is the TAp2.pl script
|
|
2 #The goal of this is to count the number of CIS present in a NR set
|
|
3 # one file is required nr.txt sorted in chromosome order!
|
|
4 # Aaron Lyman Sarver Oct 21, 2010
|
|
5 # This script takes over following the bowtie mapping and generates CIS.
|
|
6 # Update NOV15,2010 to pass library information through
|
|
7 #$Fully modified december 1 2010i
|
|
8
|
|
9 require 'config.pl';
|
|
10 require 'lib/feature_finder_methods.pl';
|
|
11 my $path = $0;
|
|
12 $path =~ s/\/\w*\.pl$//g;
|
|
13 require "$path/project_man.pl";
|
|
14 unless (-d "CIS") {
|
|
15 mkdir("CIS");
|
|
16 }
|
|
17 unless (-d "results") {
|
|
18 mkdir("results");
|
|
19 }
|
|
20
|
|
21 $proj_all = $proj."_all";
|
|
22
|
|
23 $sth = $dbh->prepare("drop table if exists lib_mappable_$proj_all");
|
|
24 $sth->execute;
|
|
25
|
|
26 $sth = $dbh->prepare("drop table if exists lib_mappable_$proj");
|
|
27 $sth->execute;
|
|
28
|
|
29 $sth = $dbh->prepare("drop table if exists illumina_hist_$proj_all");
|
|
30 $sth->execute;
|
|
31
|
|
32 $sth = $dbh->prepare("drop table if exists illumina_hist_$proj");
|
|
33 $sth->execute;
|
|
34
|
|
35 $sth = $dbh->prepare("drop table if exists bowtie_lib_$proj_all");
|
|
36 $sth->execute;
|
|
37
|
|
38 $sth = $dbh->prepare("drop table if exists bowtie_lib_$proj");
|
|
39 $sth->execute;
|
|
40
|
|
41 $sth = $dbh->prepare("drop table if exists metadata_$proj_all");
|
|
42 $sth->execute;
|
|
43
|
|
44
|
|
45 open DIN, "< data/meta.tab";
|
|
46 @met;
|
|
47 while (defined($line = <DIN>)) {
|
|
48 chomp $line;
|
|
49 @field= split(/\t/, $line);
|
|
50 push (@met,$line);
|
|
51 }
|
|
52
|
|
53 $proj_all = $proj."_all";
|
|
54 $var=shift(@met);
|
|
55
|
|
56 $sth = $dbh->prepare("create table lib_mappable_$proj_all select * from lib_mappable_$var");
|
|
57 $sth->execute;
|
|
58 $sth = $dbh->prepare("create table illumina_hist_$proj_all select * from illumina_hist_$var");
|
|
59 $sth->execute;
|
|
60 $sth = $dbh->prepare("create table bowtie_lib_$proj_all select * from bowtie_lib_$var");
|
|
61 $sth->execute;
|
|
62 $sth = $dbh->prepare("create table metadata_$proj_all select * from metadata_$var");
|
|
63 $sth->execute;
|
|
64
|
|
65 foreach $var(@met) {
|
|
66 $sth = $dbh->prepare("insert into lib_mappable_$proj_all select * from lib_mappable_$var");
|
|
67 $sth->execute;
|
|
68 $sth = $dbh->prepare("insert into illumina_hist_$proj_all select * from illumina_hist_$var");
|
|
69 $sth->execute;
|
|
70 $sth = $dbh->prepare("insert into bowtie_lib_$proj_all select * from bowtie_lib_$var");
|
|
71 $sth->execute;
|
|
72 $sth = $dbh->prepare("insert into metadata_$proj_all select * from metadata_$var");
|
|
73 $sth->execute;
|
|
74 }
|
|
75
|
|
76 unless(-e "data/metadata.tab") {
|
|
77 $sth = $dbh->prepare("select library, descriptor, type from metadata_$proj_all");
|
|
78 $sth->execute;
|
|
79 open(my $meta_out, ">", "data/metadata.tab") || die "Unable to open data/metadata.tab for output. $!\n";
|
|
80 while ((@row) = $sth->fetchrow_array) {
|
|
81 print $meta_out join("\t", @row) . "\n";
|
|
82 }
|
|
83 close($meta_out);
|
|
84 }
|
|
85
|
|
86
|
|
87 $sth = $dbh->prepare("create table lib_mappable_$proj select distinct library, sum(total) as total from lib_mappable_$proj_all group by library;");
|
|
88 $sth->execute;
|
|
89
|
|
90 $sth = $dbh->prepare("create table illumina_hist_$proj select distinct library, chromo, start, sum(count) as count,orient from illumina_hist_$proj_all group by library,chromo,start,orient;");
|
|
91 $sth->execute;
|
|
92
|
|
93 $sth = $dbh->prepare("create table bowtie_lib_$proj select distinct library,chromo, start,stop, pos, sum(count) as count,strand, orient from bowtie_lib_$proj_all group by library,chromo,start,stop,pos,strand order by chromo,start+0,orient ;");
|
|
94 $sth->execute;
|
|
95
|
|
96 $sth = $dbh->prepare("select chromo, start, stop, concat(library,'-',count),count,strand,start,stop from bowtie_lib_$proj");
|
|
97 $sth->execute;
|
|
98 #7.2
|
|
99 open OUT, "> results/raw_$proj.BED";
|
|
100 print OUT "track type ='BED' name='raw$proj' description='all$proj' visibility=2 itemRgb='On'";
|
|
101 while ((@row) = $sth->fetchrow_array) {
|
|
102 print OUT "\n$row[0]\t$row[1]\t$row[2]\t$row[3]\t$row[4]\t$row[5]\t$row[6]\t$row[7]";}
|
|
103 close OUT;
|
|
104 #7.3
|
|
105 $sth = $dbh->prepare("drop table if exists convert_2_hex_$proj");
|
|
106 $sth->execute;
|
|
107 $sth = $dbh->prepare("create table convert_2_hex_$proj (orient varchar(5), hex varchar(20))");
|
|
108 $sth->execute;
|
|
109 $sth = $dbh->prepare("insert into convert_2_hex_$proj VALUES(\"A\", \"255,0,0\")");
|
|
110 $sth->execute;
|
|
111 $sth = $dbh->prepare("insert into convert_2_hex_$proj VALUES(\"B\", \"0,0,255\")");
|
|
112 $sth->execute;
|
|
113 $sth = $dbh->prepare("insert into convert_2_hex_$proj VALUES(\"U\", \"0,0,0\")");
|
|
114 $sth->execute;
|
|
115
|
|
116 $sth = $dbh->prepare("select chromo, start, stop, concat(library,'-',count),count,strand,start,stop from bowtie_lib_$proj where count > 9");
|
|
117 ### JJE
|
|
118 #$sth = $dbh->prepare("select chromo, start, start+1, concat(library,count),count,'+',start,start+1, hex from bowtie_lib_$proj A, convert_2_hex_$proj B where A.orient = B.orient and count > 9");
|
|
119 ###
|
|
120 $sth->execute;
|
|
121 open OUT, "> results/raw10_$proj.BED";
|
|
122 print OUT "track type ='BED' name='raw10$proj' description='10$proj' visibility=2 itemRgb='On'";
|
|
123 while ((@row) = $sth->fetchrow_array) {
|
|
124 print OUT "\n$row[0]\t$row[1]\t$row[2]\t$row[3]\t$row[4]\t$row[5]\t$row[6]\t$row[7]\t$row[8]";}
|
|
125 close OUT;
|
|
126
|
|
127 &set_project_status($proj, 1, 0);
|
|
128
|