#!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) echo version = 1.24 of yvp 2012 Mar 05 # 2012 Mar 05, 1.24: supposed cosmetic change: yvp order in pubmed search terms # (must consolidate first) # 2011 Sep 04, 1.23: update documentation # 2011 Jun 12, 1.22: buffer say; no more delay # 2010 Dec 08, 1.21: show arguments if bad # 2010 Nov 25, 1.20: delay before closing to allow browser to catch up? # no - just build mechanisms for finding other scripts # 2010 Sep 09, 1.19: more open all pubmed ids!! - browse was not available # 2010 Sep 09, 1.18: open all pubmed ids!! # 2010 Feb 05, 1.17: clean up # 2010 Feb 04, 1.16: clean up # 2010 Feb 04, 1.15: allow multiple keys # 2009 Nov 16, 1.14: use 'PMID: ' as the id line # 2009 Nov 05, 1.13: fix documentation # 2009 Nov 04, 1.12: use browse script # 2009 Oct 21, 1.11: notes on eutils # 2009 Apr 22, 1.10: empty medquery call # 2009 Apr 21, 1.09: handle multiple PMIDs # 2009 Apr 17, 1.08: grab the reference if it was found! # 2008 Aug 18, 1.07: allow pages like: `yvp 2008 3 e2774` # 2008 Aug 05, 1.06: year, volume and page checks # 2007 Nov 01, 1.05: released to the web # 2007 Sep 01, 1.04: handle 1 argument case! # 2007 Jun 30, 1.03: constructed url is now given at end # 2007 Jun 19, 1.02: correct documentation # 2007 Jun 18, 1.01: allow additional tags # 2007 Jun 13, 1.00: origin from avp if (0) then echo "args $argv" # echo "0 $0" echo "1 $1" echo "2 $2" echo "3 $3" echo "4 $4" echo "5 $5" echo "last args: $argv[4-$#argv]" # qqq endif if ($#argv <= 1) then echo 'usage: yvp [year] [volume] [page]' echo 'usage: yvp [volume] [page]' echo 'usage: yvp [year] [volume] [page] [more keys]' echo 'Find article with given year/volume/page in PubMed' echo "by setting your mozilla-type browser to it." echo echo "Also, extract the reference in bibtex format." echo echo "Documentation:" echo "http://alum.mit.edu/www/toms/yvp.html" echo echo "Dependencies:" echo "* browse script - to display a url using a browser" echo -n "The browse script is" if (`which browse | grep '/'| wc -l` > 0) then echo -n "" else echo -n " NOT" endif echo " available." echo "* wgetas script - to grab a web page with wget to a new name" echo -n "The wgetas script is" if (`which wgetas | grep '/'| wc -l` > 0) then echo -n "" else echo -n " NOT" endif echo " available." echo "* buffersay" echo echo "Dr. Thomas D. Schneider" echo "National Institutes of Health" echo "schneidt@mail.nih.gov" echo "toms@alum.mit.edu (permanent)" echo "http://alum.mit.edu/www/toms (permanent)" # Note: yvp could possibly be written using Eutils: # http://www.ncbi.nlm.nih.gov/entrez/query/static/eutils_help.html # This might make it more stable. exit endif # Look for wgetas program if (1) then # debug locating wgetas which wgetas echo echo "env ---------------------" env echo echo "pwd ---------------------" pwd echo echo " path -------------------" echo "$path" echo echo "whoami ------------------" whoami echo # zzz endif if (`which wgetas| grep '/'|wc -l`> 0) then echo 'found the wgetas program' set wgetas = wgetas # buffersay 'found the wgetas program' & else # Ok, it's being called as a 'button' on the desktop set me = `whoami` set foundwgetas = 0 if (-d ~/script) then if (-f ~/script/wgetas) then set wgetas = `ls ~/script/wgetas` set foundwgetas = 1 else set foundwgetas = 0 endif else set foundwgetas = 0 endif if !($foundwgetas) then echo 'Could not find the wgetas program\!' buffersay 'Could not find the wgetas program\!' & echo 'wgetas should be in your script directory at' buffersay 'wgetas should be in your script directory at' & echo "~/script/wgetas" buffersay "~/script/yvp" & exit endif endif # Look for browse program if (1) then # debug locating browse which browse echo echo "env ---------------------" env echo echo "pwd ---------------------" pwd echo echo " path -------------------" echo "$path" echo echo "whoami ------------------" whoami echo # zzz endif if (`which browse| grep '/'|wc -l`> 0) then echo 'found the browse program' set browse = browse # buffersay 'found the browse program' & else # Ok, it's being called as a 'button' on the desktop set me = `whoami` set foundbrowse = 0 if (-d ~/script) then if (-f ~/script/browse) then set browse = `ls ~/script/browse` set foundbrowse = 1 #say found browser else set foundbrowse = 0 endif else set foundbrowse = 0 endif if !($foundbrowse) then echo 'Could not find the browse program\!' buffersay 'Could not find the browse program\!' & echo 'browse should be in your script directory at' buffersay 'browse should be in your script directory at' & echo "~/script/browse" buffersay "~/script/yvp" & exit endif endif # preset values set year = "" set volume = "" set page = "" set key = "" # example: # http://www.ncbi.nlm.nih.gov/sites/entrez?orig_db=PubMed&db=PubMed&cmd=Search&term=104%5Bvolume%5D%20AND%209278%5Bpage%5D if ($#argv == 2) then echo "year ignored, using volume and page" set volume = "$1" set page = "$2" set url = "http://www.ncbi.nlm.nih.gov/sites/entrez?orig_db=PubMed&db=PubMed&cmd=Search&term=${volume}%5Bvolume%5D%20AND%20${page}%5Bpage%5D" endif if ($#argv == 3) then echo "using year volume and page" set year = "$1" set volume = "$2" set page = "$3" set url = "http://www.ncbi.nlm.nih.gov/sites/entrez?orig_db=PubMed&db=PubMed&cmd=Search&term=${volume}%5Bvolume%5D%20AND%20${page}%5Bpage%5D" set url = "http://www.ncbi.nlm.nih.gov/sites/entrez?orig_db=PubMed&db=PubMed&cmd=Search&term=${volume}%5Bvolume%5D%20AND%20${page}%5Bpage%5D%20AND%20${year}%5Bpdat%5D" endif # if ($#argv == 4) then if ($#argv >= 4) then echo "using year volume and page and keys" set year = "$1" set volume = "$2" set page = "$3" # set key = "$4" # set key = '"'"$argv[4-$#argv]"'"' # THIS WORKS: # set key = "$argv[4-$#argv]" set key = "`echo $argv[4-$#argv] | sed 's/ / AND /g'`" # echo "number argv is $#argv" echo "the set of keys is |$key|" # exit # qqq #set url = "http://www.ncbi.nlm.nih.gov/sites/entrez?orig_db=PubMed&db=PubMed&cmd=Search&term=${volume}%5Bvolume%5D%20AND%2014%5Bpage%5D%20AND%20${year}%5Bpdat%5D" set url = "http://www.ncbi.nlm.nih.gov/sites/entrez?orig_db=PubMed&db=PubMed&cmd=Search&term=${volume}%5Bvolume%5D%20AND%20${page}%5Bpage%5D%20AND%20${year}%5Bpdat%5D%5B%20AND%20${key}" set url = "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=PubMed&Cmd=DetailsSearch&Term=${volume}%5Bvolume%5D+AND+${page}%5Bpage%5D+AND+${year}%5Bpdat%5D+AND+${key}%5BAll+Fields%5D" endif # tests: # mozillaurl "$url" # $browser -remote "openURL($url)" # check values set beep = '' if ("$year" != '') then if (("$year" > `date "+%Y"`)||("$year" < 1500)) then echo "$beep year $year is bad" echo "arguments: $argv" buffersay "$beep year $year is bad" & exit endif endif if ("$volume" != '') then if ("$volume" < 1) then echo "$beep volume $volume is bad" echo "arguments: $argv" buffersay "$beep volume $volume is bad" & exit endif endif # allow pages like e2774 in `yvp 2008 3 e2774` # if ("$page" != '') then # if ("$page" < 1) then # echo "$beep page $page is bad" # exit # endif # endif # browserurl "$url" # replace with browse 2009 nov 04: $browse "$url" echo --- url: echo "$url" # 2009 Apr 17: if one can get a PMID, call medquery with it! set tmp1 = /tmp/`whoami`1.yvp set tmp2 = /tmp/`whoami`2.yvp $wgetas "$url" $tmp1 # grep 'PMID' $tmp1|tr '<>[]' '\n\n\n\n'|grep PMID > $tmp2 # 2009 Nov 16: use 'PMID: ' to identify the PMID line grep 'PMID: ' $tmp1|tr '<>[]' '\n\n\n\n'|grep PMID > $tmp2 set n = `cat $tmp2 | wc -l` if ("$n" == 1) then # if (`echo "$line" | grep "PMID: " | wc -l` != 0) then # echo "$line" cat $tmp2 # extract the number # set pmid = `echo "$line"|sed "s/PMID: /@/"|tr '@ ' '\n\n'|head -3|tail -1` # set pmid = `cat "$tmp2"|sed "s/PMID: /@/"|tr '@ ' '\n\n'|head -3|tail -1` set pmid = `cat "$tmp2"|sed "s/PMID: /@/"|tr '@ ' '\n\n'` echo "pmid: $pmid" cd if ("$pmid" == '') then # yvp 1997 94 7937 echo 'the pmid found was empty!' buffersay 'the pmid found was empty!' & #echo "$tmp1 contains: ===========" #cat $tmp1 echo "$tmp2 contains: ===========" cat $tmp2 echo try again set pmid = `cat "$tmp2"|sed "s/PMID: /@/"|tr '@' '\n'|tail -1` if ("$pmid" == '') then echo "failed anyway" echo "arguments: $argv" buffersay "failed anyway" & exit endif endif medquery "$pmid" else if ("$n" == 0) then echo no PMID found else echo multiple PMIDs found: cat $tmp2 # unnecessary once 'browse' is functioning: #echo --- set list = `cat $tmp2 | sed 's/PMID: //' | tr -d '\n' ` # echo "$list" # set url = "http://www.ncbi.nlm.nih.gov/sites/entrez?Db=PubMed&Cmd=DetailsSearch&Term=$list" # echo "$url" # +AND+${page}%5Bpage%5D+AND+${year}%5Bpdat%5D+AND+${key}%5BAll+Fields%5D" endif endif