in reply to using WWW::Mechanize to download a link, opened fine in TextWrangler but as junk in TextEdit

When I tried your script (making up my own "data.txt" file with just the one "input" value you mentioned -- "2CU3"), I got two output files:

One, called "2CU3.html", contained the output of Data::Dumper, as expected; this was a fairly big file, and probably not the one that you really intend to use with any sort of text editor.

The other, whose file name was this long url string:

downloadFile.do?fileFormat=FASTA&compression=NO&structureId=2CU3
was pretty small (188 bytes), containing just the following four lines of plain text:
>2CU3:B|PDBID|CHAIN|SEQUENCE MVWLNGEPRPLEGKTLKEVLEEMGVELKGVAVLLNEEAFLGLEVPDRPLRDGDVVEVVALMQGG >2CU3:A|PDBID|CHAIN|SEQUENCE MVWLNGEPRPLEGKTLKEVLEEMGVELKGVAVLLNEEAFLGLEVPDRPLRDGDVVEVVALMQGG
This latter file was perfectly legible with TextEdit on my mac (osx 10.6.4) -- that is, when I just cat the file content out in a Terminal window (which is where the above lines were copy/pasted from), it looks the same as when I open it in TextEdit.

I've never used TextWrangler (don't have it installed), so I don't know if it would look any different there. But I don't see a need to try, since TextEdit seems to be showing me the exact content of the FASTA file, without any trouble.

So, what do you mean, exactly, when you say "it's just junk in textedit"?

BTW, I would suggest that you change your method of coming up with an output file name for the FASTA files. Having question marks and ampersands in file names can be a real drag if you ever end up doing command-line shell operations on them. It might be sufficient just to add one line of code:

$filename =~ s[^.+/][]; # you have this one already $filename =~ tr/?&/_/; # just add this one (turns all ? and & int +o _)
If any of the urls ever contain a space, asterisk, semi-colon, exclamation mark, vertical-bar (|), parens, brackets, or single or double quotes, you'll want to add those to ? and & in the tr/// statement, as well.

One last point -- I don't know for sure, but maybe if you added a ".txt" extension to the output FASTA file name, your TextEdit might behave better? (When I used TextEdit, it opened the file just fine as-is, but I could imagine the possibility of "user preferences" having some unexpected side-effect...)

  • Comment on Re: using WWW::Mechanize to download a link, opened fine in TextWrangler but as junk in TextEdit
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: using WWW::Mechanize to download a link, opened fine in TextWrangler but as junk in TextEdit
by nurulnad (Acolyte) on Aug 19, 2010 at 13:50 UTC
    Thank you for the advice. I'll keep that in mind. You might have just saved days of work for me in the future by just telling me that.

    I appreciate you trying out the code. I wonder why it works for you and not for me. However I've tried another method, which is using the WWW::PDB module and that works like a charm.