ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/yamap/quick_splitblast.pl
Revision: 1.1
Committed: Wed Dec 13 10:48:58 2006 UTC (9 years, 4 months ago) by gawi79
Branch: MAIN
CVS Tags: HEAD
Log Message:
A QuickMine script

Line File contents
1 #!/usr/bin/perl
2
3 #
4 # quick_splitblast.pl
5 #
6
7
8 # split up concatenated blast reports into
9 # individual reports. Is run as part of the quickmine pipeline
10
11 use strict;
12
13 use Config::Simple;
14
15 # if toggled on print some stuff
16 my $debug = 0;
17
18 unless (@ARGV ==3) {
19 die "\n\nUsage:\n ./quick_splitblast.pl path2output ext configfile\nPlease try again.\n\n\n";}
20
21 my $path2output = shift;
22 my $ext = shift;
23 my $config_file = shift;
24
25 my $cfg = new Config::Simple($config_file);
26 my $blast_programme = $cfg->param('PARAMS.blast_programme');
27
28 my $input = $ext.'.complete.blast';
29 #my $end = 'SELF_blastp';
30 my $end = "SELF_"."$blast_programme";
31
32 my ($tag, @tags, $file, $dir_name, $filename, $blast_type);
33
34 my @file = ();
35 my $directory;
36
37 open (TAGS, "$path2output/abbr.list") or die "can't open abbr.list file";
38 while ($tag = <TAGS>)
39 {
40 chomp($tag);
41 push (@tags, $tag);
42 }
43
44 foreach $tag (@tags)
45 {
46 print "$tag\n";
47 $file = "$tag"."$input";
48 $directory = "$tag".".dir";
49 system ("mkdir $path2output/$directory");
50 print "TAG: $tag - Counting orphans $file\n";
51 open (IN, "$path2output/$file") or next;
52 my $count = 0;
53 my $recent = 0;
54 while (my $line = <IN>)
55 {
56 if ($line =~m/(BLAST[P|N|X]) 2\.2\.(1\d)/)
57 {
58 $blast_type = $1;
59 if ($1 == 14)
60 {
61 $recent = 1;
62 }
63 else
64 {
65 if ($count > 0)
66 {
67 print OUT @file;
68 close OUT;
69 print "filename = $filename\n";
70
71 @file = ();
72
73 }
74
75 }
76 }
77 if ($recent == 0)
78 {
79 push (@file, $line);
80
81 # get the filename information from the query line
82 if ($line =~ /Query\=/)
83 {
84 $count++;
85 $line =~m/(Query\= )(.+)(orf)(\d+)/o;
86 my $query_name = "$2$3$4";
87 $query_name =~s/\s//;
88 if ($debug)
89 {
90 print "\nQUERY: $query_name\n";
91 }
92 # since a genome report, we only want the original
93 # abbreviation
94 $dir_name = $2;
95 $filename = $query_name.".fasta."."$end";
96
97 if ($debug)
98 {
99 print "$filename\n";
100 }
101 open (OUT, ">$path2output/$directory/$filename") or die "can't write to output file\n";
102
103 } # end if Query
104 }
105 # get the filename information from the query line
106 if ($recent == 1)
107 {
108 if ($line =~ /Query\=/)
109 {
110 if ($count > 0)
111 {
112 print OUT @file;
113 close OUT;
114
115 @file = ();
116
117 }
118 $count++;
119 $line =~m/(Query\= )(.+)(orf)(\d+)/o;
120 my $query_name = "$2$3$4";
121 $query_name =~s/\s//;
122 if ($debug)
123 {
124 print "\nQUERY: $query_name\n";
125 }
126 # since a genome report, we only want the original
127 # abbreviation
128 $dir_name = $2;
129 $filename = $query_name.".fasta."."$end";
130
131 if ($debug)
132 {
133 print "$filename\n";
134 }
135 open (OUT, ">$path2output/$directory/$filename") or die "can't write to output file\n";
136
137 } # end if Query
138 if ($line =~ /Database\:/)
139 {
140 if ($count > 0)
141 {
142 print OUT @file;
143 close OUT;
144 @file = ();
145
146 }
147 open (OUT, ">$path2output/$directory/$tag"."_blast_parameters") or die "can't write to output file\n";
148 }
149
150
151 if ($count > 0)
152 {
153 push (@file, $line);
154 }
155 }
156
157 } # end while <IN>
158 print OUT @file;
159 close OUT;
160 @file = ();
161 print "Total number of blast report files created: $count\n";
162
163
164 }