ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/yamap/crunchtoxls.pl
Revision: 1.1.1.1 (vendor branch)
Committed: Thu Sep 7 15:35:21 2006 UTC (9 years, 8 months ago) by knirirr
Branch: MAIN, cehox
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
Log Message:
Imported sources

Line File contents
1 #!/usr/bin/perl
2
3 # crunchtoxls.pl
4 # a script to read mspcrunch files from YAMAP output directories
5 # and write a whopping excel spreadsheet with them all in
6 # OR write all top hits to the same file
7
8 use strict;
9 use File::Basename;
10 use Spreadsheet::WriteExcel;
11 use Getopt::Std;
12
13 # options
14 # t: output top hits
15 # a: output all hits
16 my %opts=();
17 getopts('ta',\%opts);
18
19 unless (@ARGV)
20 {
21 die "Usage: ./crunchtoxls.pl <infiles>\n";
22 }
23
24 my @crunchfiles = @ARGV;
25 my @headers = qw(blast_score percent_id query_start query_end file subj_start subj_end subj_id subj_name);
26
27
28 # all hits into one file, one genome per spreadsheet
29 if (defined $opts{a})
30 {
31 my $outfile = "yamap_out/blast_all.xls";
32 my $workbook = Spreadsheet::WriteExcel->new("$outfile");
33 foreach my $cf (@crunchfiles)
34 {
35 my $sheet_name = &basename($cf);
36 my $worksheet = $workbook->add_worksheet($sheet_name);
37 open (IN, "<$cf") or die "Can't open $cf: $!";
38 for (my $j = 0; $j<=((scalar @headers)-1); $j++)
39 {
40 $worksheet->write(0,$j,$headers[$j]);
41 }
42 my $row = 1;
43 while (my $line = <IN>)
44 {
45 chomp($line);
46 my @parts = split(/\s+/, $line);
47 for (my $i=0;$i<=7; $i++)
48 {
49 $worksheet->write($row,$i,$parts[$i]);
50 }
51 my $out;
52 for (my $i=8;$i<=((scalar @parts)-1); $i++)
53 {
54 $out .= "$parts[$i] ";
55 }
56 $worksheet->write($row,8,$out);
57 $row++;
58 }
59 close IN;
60 }
61 }
62 # top hits
63 if (defined $opts{t})
64 {
65 my $outfile = "yamap_out/blast_top.xls";
66 my $workbook = Spreadsheet::WriteExcel->new("$outfile");
67 my $sheet_name = "top_hits";
68 my $worksheet = $workbook->add_worksheet($sheet_name);
69 $worksheet->write(0,0,"query");
70 for (my $j = 0; $j<=((scalar @headers)); $j++)
71 {
72 $worksheet->write(0,$j,$headers[$j]);
73 }
74 my $row = 1;
75 foreach my $cf (@crunchfiles)
76 {
77 open (IN, "<$cf") or die "Can't open $cf: $!";
78 my @lines = <IN>;
79 my $line = $lines[0];
80 chomp($line);
81 my @parts = split(/\s+/, $line);
82
83 # a is needed to print in the combined worksheet
84 my $subj_name = [split(/\//, $cf)]->[-1];
85 $worksheet->write($row,0,[split(/\./,$subj_name)]->[0]);
86 for (my $i=0;$i<=7; $i++)
87 {
88 $worksheet->write($row,$i+1,$parts[$i]);
89 }
90 my $out;
91 for (my $i=8;$i<=((scalar @parts)-1); $i++)
92 {
93 $out .= "$parts[$i] ";
94 }
95 $worksheet->write($row,9,$out);
96 $row++;
97 close IN;
98 }
99 }