├── pythonScripts ├── G2K.py └── rename.py ├── LICENSE ├── README.md └── oscerBashFunctions.sh /pythonScripts/G2K.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | from math import exp 3 | import sys 4 | """ 5 | OU Board of Regents 6 | 7 | Blaine Mooers, PhD 8 | OUHSC 9 | 4 April 2019 10 | 11 | MIT License 12 | """ 13 | print('Usage: G2K.py ') 14 | print('Assume standard conditions at 25C.') 15 | RT = 0.592 16 | 17 | try: 18 | deltaG = sys.argv[1] 19 | except: 20 | print('Please provide Gibbs free energy in Kcal/mol after ./G2K.py on the command line! Please include the proper sign.') 21 | 22 | fdeltaG = float(deltaG) 23 | 24 | print('Entered delta G (kcal/mol): ', deltaG) 25 | 26 | Keq = exp(fdeltaG/RT) 27 | print('Keq = ', '{:.3e}'.format(Keq)) 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Blaine Mooers and the University of Oklahoma Board of Regents 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![version](https://img.shields.io/static/v1?label=bashFunctions4oscer&message=0.1&color=brightcolor) 2 | [![license: mit](https://img.shields.io/badge/license-mit-blue.svg)](https://opensource.org/licenses/mit) 3 | 4 | 5 | # Bash functions to ease work on the University of Oklahoma's Supercomputer 6 | 7 | The University of Oklahoma's supercomputer is called *Schooner* and is run by the Oklahoma Center for Supercomputing Education and Research [(OSCER)](https://www.ou.edu/oscer). 8 | 9 | The supercomputer uses the [SLURM](https://slurm.schedmd.com/overview.html) job queuing software. 10 | Some of the functions ease the use of this system. 11 | Other functions ease doing boring tasks. 12 | 13 | These functions can be adapted to run on local unix-like machines (e.g., macOS and Linux)! 14 | The file paths will need editing. 15 | The bash script calls two Python scripts in the subfolder. 16 | 17 | May this script inspire you to write new bash functions! 18 | 19 | ## Usage in bash or zsh shells 20 | 21 | These functions work in either bash or zsh shells. 22 | Source the .bashFunctions file from your .bashrc or .zshrc file. 23 | Then, enter the function name in the terminal and hit return or enter to get a printout in the terminal of the documentation, which includes examples. 24 | 25 | ## Useful functions of note 26 | 27 | - The *gac* function combines `git add` and `git commit -m`. 28 | - The *take* function combines `mkdir` and `cd` to the new directory. 29 | - The *rmspaces* function removes those annoying whitespaces in the filenames of all files in the current directory. 30 | - The *rmunderscores* function removes underscores in the filenames of all files in the current directory. 31 | - The *rmcommas* function removes commas in the filenames of all files in the current directory. 32 | 33 | 34 | ## Table of function names and descriptions (planned) 35 | 36 | 37 | ## Related repositories 38 | 39 | - [emacs4oscer](https://github.com/MooersLab/emacs4oscer) 40 | - [vimrc4oscer](https://github.com/MooersLab/vimrc4oscer) 41 | 42 | ## Sources of funding 43 | 44 | - NIH: R01 CA242845 45 | - NIH: R01 AI088011 46 | - NIH: P30 CA225520 (PI: R. Mannel) 47 | - NIH: P20 GM103640 and P30 GM145423 (PI: A. West) 48 | 49 | -------------------------------------------------------------------------------- /pythonScripts/rename.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function 4 | import argparse 5 | import os 6 | import fnmatch 7 | import sys 8 | import shutil 9 | import re 10 | 11 | 12 | """ 13 | 14 | Replace all occurences of 'foo' with 'bar' 15 | "foo-foo.txt" >> "bar-bar.txt" 16 | 17 | rename.py . 'foo' 'bar' -s 18 | 19 | Only replace 'foo' at the beginning of the filename 20 | "foo-foo.txt" >> "bar-foo.txt" 21 | ren.py . '^foo' 'bar' -s 22 | 23 | Rename "spam.txt" to "spam.py" 24 | ren.py . '(.+)\.txt' '\1.py' -s 25 | 26 | Rename "12-lovely-spam.txt" to "lovely-spam-12.txt" 27 | # (assuming two digits at the beginning and a 3 character extension 28 | ren.py . '^(\d{2})-(.+)\.(.{3})' '\2-\1.\3' -s 29 | 30 | NOTE: don't forget to add -w when you tested the results and want to actually write the changes. 31 | """ 32 | 33 | pattern_old = re.compile(args.search_for) 34 | 35 | for path, dirs, files in os.walk(os.path.abspath(args.root_folder)): 36 | 37 | for filename in fnmatch.filter(files, "*.*"): 38 | 39 | if pattern_old.findall(filename): 40 | new_name = pattern_old.sub(args.replace_with, filename) 41 | 42 | filepath_old = os.path.join(path, filename) 43 | filepath_new = os.path.join(path, new_name) 44 | 45 | if not new_name: 46 | print('Replacement regex {} returns empty value! Skipping'.format(args.replace_with)) 47 | continue 48 | 49 | print(new_name) 50 | 51 | if args.write_changes: 52 | shutil.move(filepath_old, filepath_new) 53 | else: 54 | if not args.suppress_non_matching: 55 | print('Name [{}] does not match search regex [{}]'.format(filename, args.search_for)) 56 | 57 | 58 | if __name__ == '__main__': 59 | 60 | parser = argparse.ArgumentParser(description='Recursive file name renaming with regex support') 61 | 62 | parser.add_argument('root_folder', 63 | help='Top folder for the replacement operation', 64 | nargs='?', 65 | action='store', 66 | default='.') 67 | parser.add_argument('search_for', 68 | help='string to search for', 69 | action='store') 70 | parser.add_argument('replace_with', 71 | help='string to replace with', 72 | action='store') 73 | parser.add_argument('-w', '--write-changes', 74 | action='store_true', 75 | help='Write changes to files (otherwise just simulate the operation)', 76 | default=False) 77 | parser.add_argument('-s', '--suppress-non-matching', 78 | action='store_true', 79 | help='Hide files that do not match', 80 | default=False) 81 | 82 | args = parser.parse_args(sys.argv[1:]) 83 | 84 | print(args) 85 | rename_files(args) 86 | -------------------------------------------------------------------------------- /oscerBashFunctions.sh: -------------------------------------------------------------------------------- 1 | # My bash functions for working on remote computers like the U of Oklahoma supercomputer, which uses the SLURM job queueing software. 2 | # These functions can be adapted for use a local unix-like computer. 3 | # 4 | # I source this file from my .bashrc. 5 | # You have to source .bashrc or .bashBashAliases to reactivate after editing. 6 | # 7 | # Use "return" instead of "exit" in the functons of sourced bash files. 8 | # 9 | # The use of Vim to edit files can lead to inserting colons where unintended when escaping the insert mode to go into the command mode. 10 | # These misplaced colons can raise hell! 11 | # You can use nano (or Emacs :) ) instead. 12 | 13 | 14 | ####### aliases to bash commands 15 | 16 | # bash functions 17 | 18 | function bs { 19 | echo "Change shell to bash" 20 | ehco "Usage: bs" 21 | chsh -s /bin/bash 22 | } 23 | 24 | ### C 25 | 26 | function ccase { 27 | if [ $# -lt 1 ]; then 28 | echo 1>&2 "$0: not enough arguments" 29 | echo "Usage: rename orignal replacement" 30 | return 2 31 | elif [ $# -gt 1 ]; then 32 | echo 1>&2 "$0: too many arguments" 33 | echo "Usage: ccase phrase" 34 | fi 35 | echo "$1" 36 | arr=($1) 37 | printf %s "${arr[@]^}" 38 | } 39 | 40 | 41 | function continueSir { 42 | echo "Function to continue SIR2014 trials." 43 | echo "Usage: consir2014" 44 | echo "Run mvdone finished.txt 2371aug22' first" 45 | rm unfinished.txt && 46 | uf > unfinished.txt && 47 | nohup ./relaunch.sh 2371tpsdm & 48 | } 49 | 50 | function ci { 51 | echo "Checking in on jobs running on Schooner." 52 | cj && 53 | ds && 54 | echo "Change directory to ./sir2014trials/2371tpsdm" && 55 | 2371 && 56 | cntpdb && 57 | echo "Count unfinished trials." && 58 | cntuf && 59 | echo "Consider runing a command like: mvdone2scratch finished.txt 2371tpsdm23August2019" 60 | } 61 | 62 | 63 | function cj { 64 | echo "cj ==: checkjobs.sh" 65 | echo "List pending and running jobs for user bmooers." 66 | printf "Pending Jobs\n" && 67 | squeue -u bmooers -t PENDING -o "%.10i %.24P %.8j %.8u %.8T %.10M %.9l %.6D %R" | sed -n 'p;$=' && 68 | printf "\nRunning Jobs\n" && 69 | squeue -u bmooers -t RUNNING -o "%.10i %.24P %.8j %.8u %.8T %.10M %.9l %.6D %R" | sed -n 'p;$=' 70 | } 71 | 72 | function cpending { 73 | echo "Check pending jobs:" 74 | printf "Pending Jobs\n" && 75 | squeue -u bmooers -t PENDING -o "%.10i %.24P %.8j %.8u %.8T %.10M %.9l %.6D %R" | sed -n 'p;$=' 76 | } 77 | 78 | 79 | function crunning { 80 | echo "Check running jobs for bmooers:" 81 | printf "Running Jobs\n" && 82 | squeue -u bmooers -t RUNNING -o "%.10i %.24P %.8j %.8u %.8T %.10M %.9l %.6D %R" | sed -n 'p;$=' 83 | } 84 | 85 | 86 | function cs { 87 | echo="Change shell to csh" 88 | echo="Usage: cs" 89 | chsh -s /bin/csh 90 | } 91 | 92 | function dcase { 93 | if [ $# -lt 1 ]; then 94 | echo 1>&2 "$0: not enough arguments" 95 | echo "Usage: rename orignal replacement" 96 | return 2 97 | elif [ $# -gt 1 ]; then 98 | echo 1>&2 "$0: too many arguments" 99 | echo "Usage: dcase phrase." 100 | fi 101 | echo "$1" 102 | arr=($1) 103 | printf %s "${arr[@]^}" 104 | } 105 | 106 | # spinal_to_upper "some-string-like-this" 107 | # returns "SomeStringLikeThis" 108 | function spinal_to_upper{ 109 | IFS=- read -ra str <<<"$1" 110 | printf '%s' "${str[@]^}" 111 | } 112 | 113 | function cntfiles { 114 | echo "Count the files in the directory." 115 | echo "Usage: cntfiles." 116 | find . -type f | wc -l 117 | } 118 | 119 | function cntdir { 120 | echo "Count the directories in the current directory." 121 | echo "Usage: cntdir" 122 | find . -mindepth 1 -maxdepth 1 -type d | wc -l 123 | } 124 | 125 | function cntabi { 126 | echo "Count the number of *_abi.mtz files in subfolders." 127 | echo "Usage: cntmtz" 128 | ls -dq */*_abi.mtz | wc -l 129 | } 130 | 131 | function cntpdb { 132 | echo "Count the number of pdb files in subfolders." 133 | echo "Usage: cntpdb" 134 | ls -dq */*.pdb | wc -l 135 | find ./ -mindepth 1 -maxdepth 1 -type d '!' -exec test -e "{}/*_([1-9999]|****).pdb" ';' -print | wc -l 136 | } 137 | 138 | function cntTrials { 139 | echo "Count the number of Trails attemptedminus 1" 140 | if [ $# -lt 1 ]; then 141 | echo 1>&2 "$0: not enough arguments" 142 | echo "Usage: cntTrials 1524.out" 143 | return 2 144 | elif [ $# -gt 1 ]; then 145 | echo 1>&2 "$0: too many arguments" 146 | echo "Usage: cntTrials 1524.out" 147 | return 2 148 | fi 149 | #!/bin/bash 150 | x=$(grep -o Trial "$1" | wc -l) 151 | y=$(($x - 1)) 152 | printf "%d\t%s\n" $y "Trials run" 153 | echo "Success!" 154 | } 155 | 156 | function cntuf { 157 | echo "Count subfolders in a project directory without a pdb file." 158 | echo "Usage: cntuf" 159 | find ./ -type d -name '*startphase*' | while read a ; 160 | do if [ ! -f $a/*_****.pdb ]; 161 | then echo $a; 162 | fi; 163 | done | wc -l 164 | } 165 | 166 | function cntTimedOut { 167 | echo "Count subfolders in a project directory without a pdb file." 168 | echo "Usage: cntuf" 169 | find ./ -type d -name '*startphase*' | while read a ; 170 | do if [ ! -f $a/*_****.pdb ]; 171 | then echo $a; 172 | fi; 173 | done | wc -l 174 | } 175 | 176 | function ct { 177 | echo "Compile tex file and open with skim." 178 | if [ $# -lt 1 ]; then 179 | echo 1>&2 "$0: not enough arguments" 180 | echo "Usage: ./compile.sh baseOfTexFileName" 181 | echo "Note absence of file extension .tex" 182 | return 2 183 | elif [ $# -gt 1 ]; then 184 | echo 1>&2: 185 | "$0: too many arguments" 186 | echo "Usage: ct baseOfTexFileName" 187 | echo "Note absence of file extension .tex" 188 | return 2 189 | fi 190 | 191 | #filename=$(basename -- "$1") 192 | #extension="${filename##*.}" 193 | 194 | #if extension=".tex"; then 195 | # echo "Do NOT supply the file extension." 196 | #fi 197 | 198 | #if extension=".ltx"; then 199 | # echo "Do NOT supply the file extension." 200 | #fi 201 | 202 | pdflatex -shell-escape "$1".tex && 203 | open -a Skim "$1".pdf 204 | } 205 | 206 | ### D 207 | 208 | function dirtree { 209 | echo "Get directory tree of specified directory. May have to install tree from external repository." 210 | if [ $# -lt 1 ]; then 211 | echo 1>&2 "$0: not enough arguments" 212 | echo "Usage: dirtree " 213 | echo "Example: tree -F -a --dirsfirst 512RNAdrugCrystallization" 214 | elif [ $# -gt 1 ]; then 215 | echo 1>&2 "$0: too many arguments" 216 | echo "Usage: dirtree " 217 | echo "Example: tree -F -a --dirsfirst 512RNAdrugCrystallization" 218 | fi 219 | tree -F -a --dirsfirst $1; 220 | } 221 | 222 | function dssr { 223 | if [ $# -lt 1 ]; then 224 | echo 1>&2 "$0: not enough arguments" 225 | echo "Usage: rename orignal replacement" 226 | return 2 227 | elif [ $# -gt 1 ]; then 228 | echo 1>&2 "$0: too many arguments" 229 | echo "Usage: dssr filestemOfPDBfile" 230 | echo "Note add ^ in front of first argument when phrase is at the beginning of the line." 231 | fi 232 | echo "Runs dssr on RNA." 233 | echo "Usage: dssr filestemOfPDBfile." 234 | mkdir $1'dssrAnalysis' 235 | cd $1'dssrAnalysis' 236 | x3dna-dssr -i='../'$1.'pdb' 237 | cd .. 238 | } 239 | 240 | ### E 241 | 242 | ### F 243 | 244 | 245 | ### G 246 | 247 | function G2K { 248 | if [ $# -lt 1 ]; then 249 | echo 1>&2 "$0: not enough arguments" 250 | echo "Convert Gibbs Free energy to partition coefficient K." 251 | echo "Usage: ./G2K.py -8.2" 252 | echo "Note that the delta G knot is in kcal/mol." 253 | elif [ $# -gt 1 ]; then 254 | echo 1>&2 "$0: too many arguments" 255 | echo "Usage: ./G2K.py -8.2" 256 | echo "Note absence of file extension .tex" 257 | fi 258 | /home/bmooers/pythonScripts/G2K.py $1; 259 | } 260 | 261 | function gac { 262 | echo "Function to git add a file and then commit the changes with a message." 263 | echo "Takes the name of a file and the message in a string." 264 | echo "Must set up repository in advance of using this function." 265 | if [ $# -lt 2 ]; then 266 | echo 1>&2 "$0: not enough arguments" 267 | echo "Usage: gca filename 'message about the commit'" 268 | return 2 269 | elif [ $# -gt 2 ]; then 270 | echo 1>&2 "$0: too many arguments" 271 | echo "Usage: gct " 272 | echo "Note absence of file extension .tex" 273 | return 2 274 | fi 275 | git add "$1" 276 | git commit -m "$2" "$1" 277 | } 278 | 279 | 280 | 281 | function gct { 282 | echo "Function to git commit changes to one tex file." 283 | echo "Takes the basename as a command line argument." 284 | echo "Must set up repository in advance of using." 285 | if [ $# -lt 1 ]; then 286 | echo 1>&2 "$0: not enough arguments" 287 | echo "Usage: gct baseOfTexFileName" 288 | echo "Note absence of file extension .tex" 289 | return 2 290 | elif [ $# -gt 1 ]; then 291 | echo 1>&2 "$0: too many arguments" 292 | echo "Usage: gct " 293 | echo "Note absence of file extension .tex" 294 | return 2 295 | fi 296 | git add "$1".tex 297 | git commit -m "Added new text in $1.tex" "$1".tex 298 | } 299 | 300 | function gcpml { 301 | echo "Function to git commit changes to one tex file." 302 | echo "Takes the basename as a command line argument." 303 | echo "Must set up repository in advance of using." 304 | if [ $# -lt 1 ]; then 305 | echo 1>&2 "$0: not enough arguments" 306 | echo "Usage: gct baseOfTexFileName" 307 | echo "Note absence of file extension .pml" 308 | return 2 309 | elif [ $# -gt 1 ]; then 310 | echo 1>&2 "$0: too many arguments" 311 | echo "Usage: gct baseOfTexFileName" 312 | echo "Note absence of file extension .pml" 313 | return 2 314 | fi 315 | 316 | git add "$1".pml 317 | git commit -m "Added new text in $1.pml" "$1".pml 318 | } 319 | 320 | function gcpy { 321 | if [ $# -lt 1 ]; then 322 | echo 1>&2 "$0: not enough arguments" 323 | echo "Usage: gct baseOfTexFileName" 324 | echo "Note absence of file extension .tex" 325 | return 2 326 | elif [ $# -gt 1 ]; then 327 | echo 1>&2 "$0: too many arguments" 328 | echo "Usage: gct baseOfTexFileName" 329 | echo "Note absence of file extension .tex" 330 | return 2 331 | fi 332 | echo "Function to git commit changes to one py file." 333 | echo "Takes the basename as a command line argument." 334 | echo "Must set up repository in advance of using." 335 | 336 | git add "$1".py 337 | git commit -m "Added new text in $1.py" "$1".py 338 | } 339 | 340 | function gcr { 341 | echo "Function to git commit changes to one *.R file." 342 | echo "Takes the basename as a command line argument." 343 | echo "Must set up repository in advance of using." 344 | 345 | if [ $# -lt 1 ]; then 346 | echo 1>&2 "$0: not enough arguments" 347 | echo "Usage: gcr baseOfTexFileName" 348 | echo "Note absence of file extension .R" 349 | return 2 350 | elif [ $# -gt 1 ]; then 351 | echo 1>&2 "$0: too many arguments" 352 | echo "Usage: gcr baseOfTexFileName" 353 | echo "Note absence of file extension .R" 354 | return 2 355 | fi 356 | 357 | git add "$1".R 358 | git commit -m "Added new text in $1.R" "$1".R 359 | } 360 | 361 | function getpdb{ 362 | echo "Get PDB coordinate file from the Protein Data Bank." 363 | if [ $# -lt 1 ]; then 364 | echo 1>&2 "$0: not enough arguments" 365 | echo "Usage: getpdb " 366 | echo "Example: getpdb 4rj1." 367 | elif [ $# -gt 1 ]; then 368 | echo 1>&2 "$0: too many arguments" 369 | echo "Usage: getpdb " 370 | echo "Example: getpdb 4rj1." 371 | fi 372 | /Users/blaine/Scripts/PythonScripts/pdb_get.py $1; 373 | } 374 | 375 | function google { 376 | echo "send a search term to google from the command line" 377 | echo "Example: google OUHSC biochemistry" 378 | echo "Example: google OUHSC Links for Molecular Structure Analysis" 379 | search="" 380 | echo "Googling: $@" 381 | for term in $@; do 382 | search="$search%20$term" 383 | done 384 | open "http://www.google.com/search?q=$search" 385 | } 386 | 387 | ### H 388 | function helan { 389 | echo "Runs X3DNA's find_pair and analyze on dsRNA." 390 | echo "Usage: helanl filestemOfPDBfile." 391 | mkdir $1'helcialAnalysis' 392 | cd ./$1'helcialAnalysis' 393 | $X3DNA/bin/find_pair -s ../$1'.pdb' $1'.inp' 394 | $X3DNA/bin/analyze $1'.inp' 395 | } 396 | 397 | ### I 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | ### J 406 | function jpt { 407 | # Fires-up a Jupyter notebook by supplying a specific port 408 | jupyter notebook --no-browser --port=$1 409 | } 410 | 411 | 412 | ### K 413 | 414 | 415 | ### L 416 | 417 | function lsf { 418 | echo "Current path: $PWD" 419 | ls -ltrG 420 | } 421 | 422 | 423 | function lsnoabi { 424 | echo "List folders with *_abi.mtz absent." 425 | find `pwd` -mindepth 1 -maxdepth 1 -type d '!' -exec test -e "{}/{}_abi.mtz" ';' -print 426 | } 427 | 428 | function lsnoabi2 { 429 | echo "List folders with *_abi.mtz absent. Max depth of 2." 430 | find `pwd` -mindepth 1 -maxdepth 2 -type d '!' -exec test -e "{}/{}_abi.mtz" ';' -print 431 | } 432 | 433 | function lsabi { 434 | echo "List all subfolders with *_abi.mtz present." 435 | find `pwd` -name "*"_abi.mtz -print 436 | } 437 | 438 | function lspdb { 439 | #echo "List all subfolders with *.pdb present. Print the path but not the pdb file." 440 | find `pwd` -name "*".pdb -exec dirname {} \; 441 | } 442 | 443 | ### M 444 | #mvdone() 445 | #{ 446 | #echo "Move folders in list in a text file. One folder per line." 447 | #echo "" 448 | #echo "Finds the folders with pdb files and writes the full path to txt file." 449 | #echo "Takes the name of this file and name of the folder one level up." 450 | #echo "Usage: mvdone finished.txt 1556done" 451 | #if [ $# -lt 2 ]; then 452 | # echo 1>&2 "$0: not enough arguments" 453 | # echo "Usage: mvList finished.txt 1556Done" 454 | # return 2 455 | #elif [ $# -gt 2 ]; then 456 | # echo 1>&2 "$0: too many arguments" 457 | # echo "Usage: mvdone finished.txt 1556done" 458 | # return 2 459 | #fi 460 | #lspdb > $1 461 | #mkdir ../$2 462 | #for folder in $(cat $1); 463 | # do mv "$folder" /home/bmooers/sir2014_trials/$2; 464 | #done 465 | #} 466 | 467 | 468 | 469 | function mvdone2home { 470 | echo "mvdone2home()" 471 | echo "" 472 | echo "Move folders in list in a text file finished.txt to /home/bmooers. One folder per line." 473 | echo "Use when the scratch drive is not available." 474 | echo "" 475 | echo "Finds the folders with pdb files and writes the full path to a txt file." 476 | echo "Takes as arguments the name of this txt file and name of the new folder in the home folder." 477 | echo "Usage: mvdone2home finished.txt FolderStemDone" 478 | if [ $# -lt 2 ]; then 479 | echo 1>&2 "$0: not enough arguments" 480 | echo "Usage: mvList finished.txt 1556Done" 481 | return 2 482 | elif [ $# -gt 2 ]; then 483 | echo 1>&2 "$0: too many arguments" 484 | echo "Usage: mvdone finished.txt 1556done" 485 | return 2 486 | fi 487 | mkdir /home/bmooers/$2 488 | lspdb > /home/bmooers/$2/$1 489 | for folder in $(cat /home/bmooers/$2/$1); 490 | do mv "$folder" /home/bmooers/$2; 491 | done 492 | echo "" 493 | echo "Moved finished jobs to /home/bmooers/$2. Take care not to overwrite this folder." 494 | } 495 | 496 | 497 | 498 | function mvdone2scratch { 499 | echo "mvdone2scratch()" 500 | echo "" 501 | echo "Move folders in list in a text file finished.txt to /scatch/bmooers. One folder per line." 502 | echo "" 503 | echo "Finds the folders with pdb files and writes the full path to a txt file." 504 | echo "Takes as arguments the name of this txt file and name of the new folder on the scratch disk." 505 | echo "Usage: mvdone2scratch finished.txt FolderStemDone" 506 | if [ $# -lt 2 ]; then 507 | echo 1>&2 "$0: not enough arguments" 508 | echo "Usage: mvList finished.txt 1556Done" 509 | return 2 510 | elif [ $# -gt 2 ]; then 511 | echo 1>&2 "$0: too many arguments" 512 | echo "Usage: mvdone finished.txt 1556done" 513 | return 2 514 | fi 515 | mkdir /scratch/bmooers/$2 516 | lspdb > /scratch/bmooers/$2/$1 517 | for folder in $(cat /scratch/bmooers/$2/$1); 518 | do mv "$folder" /scratch/bmooers/$2; 519 | done 520 | echo "Moved finished jobs to /scratch/bmooers/$2. Take care not to overwrite this folder. Folders can remain on the scarch disk." 521 | } 522 | 523 | 524 | 525 | 526 | ### N 527 | 528 | ### O 529 | 530 | ### P 531 | 532 | function pdfcropall { 533 | echo "pdfcrop all pdfs in a directory by trimming away the white borders." 534 | echo "Usage: pdfcropall" 535 | echo "pdbcrop must be installed. " 536 | 537 | for FILE in ./*.pdf 538 | do 539 | pdfcrop "${FILE}" "${FILE}" 540 | done 541 | } 542 | 543 | 544 | function pyc { 545 | echo "Evaluate simple math expressions with Python. Math expression must be passed inside double quotes." 546 | echo 'Example1 using built-in: pyc "110./10."' 547 | echo 'Example2 using the math module: pyc "math.sin(math.radians(90))"' 548 | echo 'To see the available math functions, enter python -c "import math;print(dir(math))"' 549 | if [ $# -lt 1 ]; then 550 | echo 1>&2 "$0: not enough arguments" 551 | echo 'Example: pyc "110./10."' 552 | return 2 553 | elif [ $# -gt 1 ]; then 554 | echo 1>&2 "$0: too many arguments" 555 | echo 'Example: pyc "110./10."' 556 | fi 557 | python -c 'import math;print(eval("'$1'"))' 558 | } 559 | 560 | alias dzpdf="rename 's/\(z-lib.org\)./\./' *.pdf" 561 | alias dzepub="rename 's/\(z-lib.org\)./\./' *.epub" 562 | 563 | ### Q 564 | 565 | 566 | ### R 567 | function rmcommas { 568 | echo "Remove commas in all filenames in a directory" 569 | echo "Usage: rmcommas" 570 | for f in *,*; 571 | do 572 | mv "$f" "${f//,/}"; 573 | done 574 | } 575 | 576 | 577 | function rmduplicates { 578 | echo "Remove duplicate files. This function will remove those duplicate pdfs that you downloaded." 579 | echo "This function requires bash version 4.0+ because it has the array function." 580 | echo "The default bash on Mac is older than version 4.0. Install a newer bash with macports or fink or homebrew." 581 | 582 | declare -A arr 583 | shopt -s globstar 584 | 585 | for file in **; 586 | do 587 | [[ -f "$file" ]] || continue 588 | read cksm _ < <(md5sum "$file") 589 | if ((arr[$cksm]++)); then 590 | echo "rm $file" 591 | fi 592 | done 593 | } 594 | 595 | 596 | function rmspaces { 597 | echo "Remove whitespaces in all filenames in a directory" 598 | echo "Usage: rmspaces" 599 | for f in *\ *; 600 | do 601 | mv "$f" "${f// /}"; 602 | done 603 | } 604 | 605 | 606 | function rmunderscores { 607 | echo "Remove underscores in all filenames in a directory" 608 | echo "Usage: rmscores" 609 | for f in *_*; 610 | do 611 | mv "$f" "${f//_/}"; 612 | done 613 | } 614 | 615 | 616 | #redoLaunch() 617 | #{ 618 | #echo "Write the unfinished jobs to a txt file. Loop over this file and write a new launch script." 619 | #echo "Usage: redoLaunch $1" 620 | #if [ $# -lt 1 ]; then 621 | # echo 1>&2 "$0: not enough arguments" 622 | # echo "Usage: redoLaunch prefix" 623 | # echo "Example: redoLaunch $1" 624 | # return 2 625 | #elif [ $# -gt 1 ]; then 626 | # echo 1>&2 "$0: too many arguments" 627 | # echo "Usage: redoLaunch prefix prefix" 628 | # exho "Example: redoLaunch $1" 629 | # return 2 630 | #fi 631 | # 632 | #rm unfinished.txt 633 | #rm newLaunch.sh 634 | #find `pwd` -type d -name '*startphase*' | while read a ; 635 | #do if [ ! -f $a/*_****.pdb ]; 636 | # then printf '%s\n' $a >> unfinished.txt 637 | #fi 638 | #done 639 | #echo "Finished writing 'unfinished.txt' (:" 640 | #for folderpath in $(cat unfinished.txt); 641 | # do printf 'sbatch %s/$1.sbatch; sleep 1m;\n' "$folderpath" >> newLaunch.sh 642 | #done 643 | #echo "Finished writing a new 'newLaunch.sh' file (:" 644 | #} 645 | 646 | 647 | #relaunch(){ 648 | #echo "Relaunch timed out jobs. Must run uf > unfinished.txt first." 649 | #echo "May want to shorten the list of jobs run at one time." 650 | # 651 | #if [ $# -lt 1 ]; then 652 | # echo 1>&2 "$0: not enough arguments" 653 | # echo "Usage: ./relaunch.sh prefix" 654 | # echo "Example: ./relaunch.sh 1524" 655 | # return 2 656 | #elif [ $# -gt 1 ]; then 657 | # echo 1>&2 "$0: too many arguments" 658 | # echo "Usage: ./relaunch.sh prefix prefix" 659 | # exho "Example: ./relaunch.sh 1524" 660 | # return 2 661 | #fi 662 | #count=1 663 | #for folderpath in $(cat unfinished.txt); 664 | #do 665 | # cp restart.sh "$folderpath"/.; 666 | # cd "$folderpath"; 667 | # echo "$folderpath"; 668 | # "$folderpath"/restart.sh "$1"; 669 | # echo 'Launched job "$count" in "$folderpath"'; 670 | # count=`expr $count + 1` 671 | #done 672 | #echo 'Finished relaunching "$count" jobs (:' 673 | #} 674 | 675 | 676 | function rename { 677 | echo "Rename filenames in current folder with the Rename.py script." 678 | if [ $# -lt 2 ]; then 679 | echo 1>&2 "$0: not enough arguments" 680 | echo "Usage: rename orignal replacement" 681 | return 2 682 | elif [ $# -gt 2 ]; then 683 | echo 1>&2 "$0: too many arguments" 684 | echo "Usage: rename orignal replacement" 685 | echo "Note add ^ in front of first argument when phrase is at the beginning of the line." 686 | return 2 687 | fi 688 | /home/bmooers/pythonScripts/rename.py . '$1' '$2' -s -w 689 | } 690 | 691 | # repeat a command a specific number of times 692 | function repeat { 693 | echo "Example usage: repeat 61 ./quizDP.py" 694 | echo "The first argument is the time in seconds that the script is delayed." 695 | echo " " 696 | echo "If the script needs to run multiple times" 697 | echo "every n seconds, try the whileLoop alias" 698 | echo "or the script ./Scripts/BashScripts/whileLoop.sh." 699 | n=$1 700 | shift 701 | while [ $(( n -= 1 )) -ge 0 ] 702 | do 703 | "$@" 704 | done 705 | } 706 | 707 | function resubmit { 708 | echo "Resubmit unfinsihed jobs to the queue." 709 | echo "Usage: resubmit sirjobname" 710 | echo "Example: resubmit 2371tpsdm" 711 | if [ $# -lt 1 ]; then 712 | echo 1>&2 "$0: not enough arguments" 713 | return 2 714 | elif [ $# -gt 1 ]; then 715 | echo 1>&2 "$0: too many arguments" 716 | return 2 717 | fi 718 | rm unfinished.txt && 719 | uf > unfinished.txt && 720 | nohup ./relaunch.sh $1 & 721 | } 722 | 723 | function rmspaces { 724 | echo "Remove whitespaces in all filenames in a directory" 725 | echo "Usage: rmspaces" 726 | for f in *\ *; 727 | do 728 | mv "$f" "${f// /}"; 729 | done 730 | } 731 | 732 | ### S 733 | 734 | function shortcursor { 735 | echo "Make shortcursor." 736 | echo "Usage: shortcursor" 737 | PS1='\u:\W\$ ' 738 | } 739 | 740 | ### T 741 | 742 | # Source: Bozhidar Batsov https://batsov.com/ 743 | function take { 744 | if [[ $1 =~ ^(https?|ftp).*\.tar\.(gz|bz2|xz)$ ]]; then 745 | takeurl "$1" 746 | elif [[ $1 =~ ^([A-Za-z0-9]\+@|https?|git|ssh|ftps?|rsync).*\.git/?$ ]]; then 747 | takegit "$1" 748 | else 749 | takedir "$@" 750 | fi 751 | } 752 | 753 | 754 | function tre { 755 | echo "Get directory tree of specified directory. May have to install tree from external repository." 756 | if [ $# -lt 1 ]; then 757 | echo 1>&2 "$0: not enough arguments" 758 | echo "Usage: tre " 759 | echo "Example: tree -F -a --dirsfirst 512RNAdrugCrystallization" 760 | elif [ $# -gt 1 ]; then 761 | echo 1>&2 "$0: too many arguments" 762 | echo "Usage: tre " 763 | echo "Example: tree -F -a --dirsfirst 512RNAdrugCrystallization" 764 | fi 765 | tree -F -a --dirsfirst $1; 766 | } 767 | 768 | 769 | 770 | ### U 771 | 772 | function uf { 773 | echo "Search subfolders in a project directory for folders without a pdb file." 774 | echo "I have had some false positives. Check the results before doing anything rash." 775 | echo "Usage: uf" 776 | find `pwd` -type d -name '*startphase*' | while read a ; 777 | do if [ ! -f $a/*_****.pdb ]; 778 | then echo $a; 779 | fi; 780 | done 781 | } 782 | 783 | function unfincnt { 784 | if [ $# -lt 2 ]; then 785 | echo 1>&2 "$0: not enough arguments" 786 | echo "Usage: unfincnt projectDirectory prefix1" 787 | return 2 788 | elif [ $# -gt 2 ]; then 789 | echo 1>&2 "$0: too many arguments" 790 | echo "Note add ^ in front of first argument when phrase is at the beginning of the line." 791 | echo "Usage: unfincnt projectDirectory prefix1" 792 | return 2 793 | fi 794 | echo "Search subfolders in a project directory for folders without a pdb file and return the number of folders." 795 | echo "I have had some false positives. Check the results before doing anything rash." 796 | echo "Prefix1 is the stem of the pdb filename." 797 | echo "Move to the directory just above the projectDirectory" 798 | echo "Usage: unfincnt projectDirectory prefix1" 799 | find "./"$1 -mindepth 1 -maxdepth 2 -type d '!' -exec test -e "{}/"$2"_([1-9999]|****).pdb" ';' -print | wc -l 800 | } 801 | 802 | ### V 803 | 804 | 805 | 806 | ### W 807 | 808 | function whileLoop { 809 | FILE1=$1 810 | echo "Runs script every 5 seconds for 10 times" 811 | echo "Usage: whileLoop scriptfile" 812 | echo "Example whileLoop quizDP2pdf.py" 813 | echo "Blaine Mooers, Oct. 29, 2017" 814 | COUNTER=0 815 | while [ $COUNTER -lt 10 ]; do 816 | echo The counter is $COUNTER 817 | ./$FILE1 818 | sleep 5 819 | let COUNTER=COUNTER+1 820 | done 821 | } 822 | 823 | ### X 824 | 825 | 826 | ### Y 827 | 828 | 829 | ### Z 830 | 831 | function zsh { 832 | echo "Change the shell language of the terminal to zsh." 833 | echo "Usage: zsh" 834 | chsh -s /bin/zsh 835 | } 836 | 837 | --------------------------------------------------------------------------------