|
楼主 |
发表于 2013-10-30 20:44:59
|
显示全部楼层
#!/usr/bin/perl -w
use LWP::Simple;
use LWP::UserAgent;
use warnings;
use strict;
if(@ARGV !=6)
{
print "USAGE(example): perl downcas.pl -infile f:/casid.txt -type 2Dor3D -outfolder f:/downcas\n";
# 0 1 2 3 4 5
}
else
{
my $filepath=$ARGV[1];
my $downcas=$ARGV[5];
my $identy;
if($ARGV[3]=~/(\d)D/)
{
$identy=($1==3)?'3D':"";
print "\n$identy\n";
}
else
{
print "USAGE(example): perl downcas.pl -infile f:/casid.txt -type 2Dor3D -outfolder f:/downcas\n";
#
exit 0;
}
print "$downcas\n";
mkdir $downcas unless -d $filepath;
my ($ua,$req,$res);
$ua = LWP::UserAgent->new;
open FH, $filepath;
while(my $id=<FH>)
{
chomp $id;
$req= HTTP::Request->new(HEAD => 'http://www.ncbi.nlm.nih.gov/pccompound/?term='.$id);
$res = $ua->request($req);
$res->request()->uri()=~/(\d+)\s*$/;
if($res->request()->uri()=~/cid\=(\d+)\s*$/)
{
my $savename=$downcas.$id.'_cid_'.$1.'.sdf';
print "find $id and download it as $savename\n";
my $newfile=$downcas.'/successdown.txt';
open FG,">>$newfile";
print FG "$id savename: $savename\n";
getstore("http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=$1&disopt=${identy}SaveSDF",$savename);
}
else
{
print "can't find $id\n";
my $newfile=$downcas.'/faildown.txt';
open FF,">>$newfile";
print FF "$id \n ";
}
}
}
补一个Perl脚本 |
|