#!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) if ($#argv == 2) then set probe = "$2" if ("$1" != '-r') then echo "two arguments given but first is not -r, (it is $1)" exit endif set justreference = true else set justreference = false set probe = "$1" if ("$1" == '-r') then echo "missing key for paper" exit endif endif if ($justreference == false) then echo version = 1.25 of pullpaper 2010 Aug 10 endif # 2011 Aug 10, 1.25: don't report tmp2 at the end for no reason ... # 2011 Apr 13, 1.24: locate Freier1986 # 2011 Apr 13, 1.23: use regular grep # 2011 Mar 11, 1.22: shut up the Klaxon! # 2011 Mar 11, 1.21: upgrade for Mac OS X # 2008 Jun 18, 1.20: location: paper -> papers # 2007 Oct 24, 1.19: use yvp to get to the paper in pubmed if klaxon goes off # 2006 Jul 05, 1.18: ignore capitalization in key by using 'grep -i' # 2005 Nov 01, 1.17: give paper reference at end # 2005 Sep 22, 1.16: could not find Krawczak.Reiss1992 ... missing from all.bib # 2005 Sep 10, 1.15: handle arguments better when -r flag only. # 2005 Sep 6, 1.14: no blanks when -r flag # 2005 Sep 6, 1.13: -r flag # 2005 Aug 31, 1.12: cleanup output # 2005 Apr 1, 1.11: pullpaper SantaLucia1998 missing } # 2004 Dec 10, 1.10: pullpaper Kornberg2000 crash on echo # 2004 Sep 10, 1.09: pullpaper Harbison.Young2004 missed pmid? # 2004 May 11, 1.08: pullpaper Zhang.Zhang1998 : C T should be removed # 2004 Apr 9, 1.07: use first and last author # 2004 Apr 9, 1.06: remove '-{}\' from author list # 2004 Apr 9, 1.05: use first author if pmid is not there # 2004 Apr 9, 1.04: set term = +++ form # 2004 Apr 9, 1.03: fix usage message # 2004 Apr 9, 1.02: sound # 2004 Apr 8, 1.01: functional!!! extract numbers if fail to find pmid # 2004 Apr 8, 1.00: origin set source = ~/papers/references/all.bib if (-f $source) then # echo using $source else set source = ~toms/papers/references/all.bib endif if ($justreference == false) then echo pull the paper whose key name is given echo by finding it in $source endif if ($#argv == 0) then echo 'usage: pullpaper [-r] [key]' echo "where 'key' is a key for a reference in" echo $source echo 'The key is used to find the Pubmed ID (pmid).' echo 'The pubmed id is then used to direct the browser' echo 'to the pubmed entry.' echo '-r flag: just give the bibtex reference and stop' echo 'Capitilaztion in the key is ignored to simplify typing.' exit else if ($justreference == false) then echo using $source endif endif set key = $1 set from = 0 # to = 20 failed for Harbison.Young200 # and gave a Klaxon set to = 20 set from = 1 set to = 60 set target = $source set tmp1 = /tmp/`whoami`1.pullpaper set tmp2 = /tmp/`whoami`2.pullpaper grep -i -A $to -B $from $probe $target > $tmp1 set bot = `sed 's/^$/@@/' $tmp1|number|grep @@|head -2|tail -1|tr -d '@ '` # echo $bot if ("$bot" == '') then echo $probe not found in $target exit endif head -$bot $tmp1 > $tmp2 if ($justreference == true) then cat $tmp2 |\ grep -v '^$' |\ cat exit endif echo Looking for entry $probe set l="`cat $tmp2|fmti 700|grep pmid`" echo ----- echo The reference is "$l": echo "$l" echo ----- if ("$l" == '') then echo "no pmid in $key" # extract pages, volume and year for another attempt grep -i -A $to -B $from $probe $target > $tmp1 echo -------- "$tmp1" cat $tmp1 echo -------- # fmti 800 $tmp1 | head -2 | tail -1 > $tmp2 fmti 800 $tmp1 | head -2 | tail -1 | tr -d '{}' > $tmp2 echo -------- "$tmp2" cat $tmp2 echo -------- set aline = `cat "$tmp2"|sed -e "s/, /,@/g"|tr "@" "\012"|grep author` echo aline is "$aline" # extract the author list: set a1 = `echo "$aline"|tr '"' "\012"|head -2|tail -1` # remove the periods: set a2 = `echo "$a1"|sed -e "s/\.//g"` # change and to AND for pubmed to search: set a3 = `echo "$a2"|sed -e "s/ and / AND /g"` # make sure that dashes in author name are zapped: set a31 = `echo "$a3"|sed -e "s/-/ /g"` # remove single characters: set a4 = `echo "$a31"|sed -e "s/ . / /g"` # remove single characters from the first one: set a5 = `echo "$a4"|sed -e "s/^. / /g"` # remove single characters AGAIN (not sure why): # but it is needed for Schneider1986 set a6 = `echo "$a5"|sed -e "s/ . / /g"` # remove '-{}\' from author list # set a7 = `echo "$a6"|tr -d '{-}\'` set a7 = `echo "$a6"|sed -e 's/-/ /g'|sed -e 's/{/ /g'|sed -e 's/}/ /g'` set a8 = `echo "$a7"|sed -e 's,/, ,g'` set alist = "$a8" while (0) echo a6: $a6 echo a7: $a7 echo a8: $a8 echo alist: $alist exit end # author = "T. D. Schneider and G. D. Stormo and L. Gold and A. Ehrenfeucht", # Schneider AND Stormo AND Gold AND Ehrenfeucht # set author = "$a6" # pubmed refuses to search with this. Use only first and last authors. echo alist: $alist set b1 = `echo "$alist"|sed -e "s/ AND /@/g"` set b2 = `echo "$b1"|tr '@' '\012'|head -1` set b3 = `echo "$b1"|tr '@' '\012'|tail -1` # remove dashes in names as Zhang.Zhang1998 which contains: # aline is author = "C.-T. Zhang and Z.-S. Lin and M. Yan and R. Zhang", # echo b1: $b1 # echo b2: $b2 # echo b3: $b3 set author = "$b2 AND $b3" echo "$author" set vline = `cat $tmp2|sed -e "s/, /,@/g"|tr "@" "\012"|grep volume` echo vline is "$vline" set volume = `echo "$vline"|tr '"' "\012"|head -2|tail -1` set pline = `cat $tmp2|sed -e "s/, /,@/g"|tr "@" "\012"|grep pages` echo pline is "$pline" set pages = `echo "$pline"|tr '"' "\012"|head -2|tail -1` set yline = `cat $tmp2|sed -e "s/, /,@/g"|tr "@" "\012"|grep year` set year = `echo "$yline"|tr '"' "\012"|head -2|tail -1` echo author: $author echo volume: $volume echo pages: $pages echo year: $year # the last page number is not in PubMed, remove it set firstpage = `echo $pages|tr '-' '\012'|head -1` echo firstpage: $firstpage # set s = "$volume&term=$firstpage&term=$year" # set s = "$author+AND+$volume+AND+$firstpage+AND+$year" # # sound klaxon & # echo "*********************************************" # echo "**** The Klaxon WARNING means: *****" # echo "**** There is no Pubmed ID found for *****" # echo "**** this reference. *****" # echo "**** (NOTE: is $to too small?) *****" # echo "**** Using volume, first page and year: *****" # echo "*********************************************" # echo "search string s is $s" # echo "volume is $volume" # echo "year is $year" # echo "firstpage is $firstpage" #exit # for now # pubmedsearch "$s" yvp $year $volume $firstpage exit endif # at this point the $l is a string for the ENTIRE entry # Break it up and isolate the pmid # echo "$l" |\ # sed -e "s/, /,@/g" |\ # tr "@" "\012" |\ # cat set pmidline = `echo "$l"|sed -e "s/, /,@/g"|tr "@" "\012"|grep pmid` echo "$pmidline" echo ----- # convert the pmidline to pmid set pmid = `echo "$pmidline"|tr '"' "\012"|head -2|tail -1` # safety check if ($pmid == '') then echo 'Failed to find a pmid\!' exit else echo the pmid is $pmid for $key pmid $pmid $1 endif echo ---------------------------------------------------------- exit # the following might be useful for debugging, but not for general use! date echo ----- # echo "$l" # echo '-----' cat $tmp2 echo -----