Hey all, I'm using Mechanize to run a batch pathway analysis by looping over a set of files containing gene names (ie I have about 500 txt files each containing a list of genes. I want to upload the list of genes in each file to the website, get an output and then move on to the next file). My code works for the first run through the loop but then gives me an error "Can't call method "value" on an undefined value at /Library/Perl/5.12/WWW/Mechanize.pm line 1407, <IN> line 1." For some reason if I close IN or if I try to empty out $geneList, it destroys this variable. However, if I don't do this, it concatenates ALL of the genes together from all of the files (which is not what I want). I'm not sure where I'm messing up, so any help would be appreciated! FYI each file is formatted such that the genes are on a single line separated by a space.

#!/usr/bin/perl #use strict; use WWW::Mechanize; # this package is based on LWP, but behaves mor +e like a browser # we need it here for easy managment of cookies, n +eeded for logon use Switch; # may not be used here, implements case:switch my $numArgs = $#ARGV+1; if ($numArgs != 2) { print "\n"; print "usage: gseaRobot <inputDir> <outputDir>\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, "</$inputDir/$filename"; #@genes=<IN>; while ($line=<IN>){ $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 c +ommand line $outfile=$outputDir."/".$filename; $m->save_content($outfile); print $response->content(); close IN; } } }

In reply to Mechanize FAIL by zampboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.