#!/usr/bin/perl #use strict; use WWW::Mechanize; # this package is based on LWP, but behaves more like a browser # we need it here for easy managment of cookies, needed for logon use Switch; # may not be used here, implements case:switch my $numArgs = $#ARGV+1; if ($numArgs != 2) { print "\n"; print "usage: gseaRobot \n"; exit(); } my $inputDir = $ARGV[0]; my $outputDir = $ARGV[1]; my $username = 'kburns@jhmi.edu'; my $loginUrl = 'http://www.broadinstitute.org/gsea/login.jsp'; my $queryUrl = 'http://www.broadinstitute.org/gsea/msigdb/annotate.jsp'; my $geneList = "$geneList"; #print $geneList,"\n"; my $geneSetName = ""; my $platform = "GENE_SYMBOL"; my $m = WWW::Mechanize->new(); ## LOGIN $m->get($loginUrl); $m->form_name('loginForm'); $m->field('j_username',$username); $m->field('j_password','password'); $response = $m->submit(); opendir (DIR, $inputDir) or die $!; while ($filename = readdir(DIR) ) { if($filename=~/.*\.txt/){ open IN, "; while ($line=){ $geneList=$line; print "$geneList\n"; $m->get($queryUrl); $m->form_name('computeOverlapsForm'); $m->field('platform',$platform); $m->field('geneList',$geneList); $m->field('geneSetName',''); $m->field('collection','C2'); ##'CP:KEGG', ##'CP:REACTOME', ##'CP', ##'CGP', ##'CP:BIOCARTA'; $response = $m->submit(); ## PERFORM DOWNLOAD $m->form_name('downloadForm'); $m->field('platform',$platform); $m->field('maxShown','10'); $m->field('geneList',$geneList); $m->field('geneSetName',''); $m->field('collection','C2'); $response = $m->submit(); ###Write to outfile in output directory stated on command line $outfile=$outputDir."/".$filename; $m->save_content($outfile); print $response->content(); close IN; } } }