annotate tools/human_genome_variation/linkToDavid.pl @ 1:cdcb0ce84a1b

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:15 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/usr/bin/env perl
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 use strict;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 use warnings;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 ###################################################
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 # linkToDavid.pl
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 # Generates a link to David for a list of gene IDs.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 ###################################################
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 if (!@ARGV or scalar @ARGV != 4) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 print "usage: linkToDavid.pl infile.tab 1basedCol idType outfile\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 exit 1;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 my $in = shift @ARGV;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 my $col = shift @ARGV;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 my $type = shift @ARGV;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 my $out = shift @ARGV;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 if ($col < 1) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 print "ERROR the column number should be 1 based counting\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 exit 1;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 my @gene;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 open(FH, $in) or die "Couldn't open $in, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 while (<FH>) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 chomp;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 my @f = split(/\t/);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 if (scalar @f < $col) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 print "ERROR there is no column $col in $in\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 exit 1;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 if ($f[$col-1]) { push(@gene, $f[$col-1]); }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36 close FH or die "Couldn't close $in, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 if (scalar @gene > 400) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 print "ERROR David only allows 400 genes submitted via a link\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 exit 1;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 my $link = 'http://david.abcc.ncifcrf.gov/api.jsp?type=TYPE&ids=GENELIST&tool=summary';
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 my $g = join(",", @gene);
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 $link =~ s/GENELIST/$g/;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 $link =~ s/TYPE/$type/;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48 #print output
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 if (length $link > 2048) {
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 print "ERROR too many genes to fit in URL, please select a smaller set\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 exit;
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 }
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53 open(FH, ">", $out) or die "Couldn't open $out, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 print FH "<html><head><title>DAVID link</title></head><body>\n",
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 '<A TARGET=_BLANK HREF="', $link, '">click here to send of identifiers to DAVID</A>', "\n",
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56 '</body></html>', "\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 close FH or die "Couldn't close $out, $!\n";
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59 exit;