#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize::Firefox; use Firefox::Application; use WWW::Scripter; my $ff = Firefox::Application->new(); my $mech = WWW::Mechanize::Firefox->new(autoclose => 1); $mech->get("http://david.abcc.ncifcrf.gov/summary.jsp"); $mech->click({ xpath => ('//*[@href="Upload a Gene List or Population"]', single => 1), synchronize => 0 }); $mech->form_name('frmManager'); $mech->set_fields( 'pasteBox' => "RRI1, YLR149C, FUN19, YBR285W, ALD3, CUE5, RTC3, AIM3, YDL199C, FMP45, AST2, GIP2, YKL091C, YKL133C, GLG2, SYM1, VHS3, YJR124C, MCH1, MHO1, IKS1, RKM1, STF2, SAC1, ATG7, YAK1", 'Identifier' => "OFFICIAL_GENE_SYMBOL", ); $mech->click ({ xpath => ('//input[@name="rbUploadType" and @value="list"]', single => 1), synchronize => 0 }); $mech->click({xpath => ('//*[@value="Submit List"]', single => 1), synchronize => 0}); $mech->back; $mech->form_name('frmManager'); $mech->set_fields( 'speciesList' => 0); $mech->click({xpath => ('//*[@value="Select Species"]', single => 1), synchronize => 0}); $mech->back; $mech->click({xpath => ('//*[@value="Functional Annotation Clustering"]', single => 1), synchronize => 0}); my $retries = 100; while ($retries-- and ! $mech->is_visible( xpath => '//*[@value="Functional Annotation Clustering"]' )) { sleep 1; $mech->back; } die "Timeout" unless $retries; my $dataurl; my @tab_info = $ff->openTabs(); foreach my $tab(@tab_info) { if ($tab->{location} =~ 'http://david.abcc.ncifcrf.gov/term2term.jsp?') { $dataurl = $tab->{location}; chomp $dataurl; } } $mech->get($dataurl); my $w = new WWW::Scripter; my @foundLinks = $mech->find_all_links(); my $filelink; foreach my $link(@foundLinks) { if (index($link->[0], ".txt") > 0) { $filelink = $link->[0]; } } $w->get($filelink); if ($w->success()) { my $content = $w->response->content; open(FILE, ">DAVID.txt"); print FILE $content; close FILE; } my $var = `wmctrl -l | grep \"DAVID\" | tail -1 | cut -f1 -d\" \"`; chomp $var; system("wmctrl -i -c \"$var\"");