2020/21
Dr. Rene Staritzbichler
$ ls *.pdb # list all PDB files
$ ls /
$ ls -lh # '-l': detailed output, '-h': human readable, e.g. 4.3GB as file size
$ cd /home/YOU/course/data/
$ touch new.txt # create empty file
$ echo "Hello" > new.txt # creates file with single line
$ echo "World" >> new.txt # append a line
$ gedit new.txt # opens text editor, file is created when saved
$ mkdir NEW
$ mkdir -p NEW/SUB/ONE_MORE/ANOTHER
$ rm rubbish.txt
$ rm -r dir/
$ head -n 12 myfile.txt
$ tail -n 33 myfile.txt | grep ATOM # write only files containing the string 'ATOM'
for f in *.pdb
do
ls -lh $f
grep ATOM $f > atoms_$f
done
Nearly the same as one liner:
for f in *.pdb; do grep ATOM $f > atoms_$f; done
cp PATH_OLD/FILE_OLD PATH_NEW/FILE_NEW # cp and rename
cp PATH_OLD/FILE_OLD PATH_NEW/. # cp to same name
cp -r DIRECTORY PATH/. # cp recursively all content of directory
mv PATH_OLD/OLD PATH_NEW/NEW # move and rename FILE OR DIRECTORY
mv PATH_OLD/OLD PATH_NEW/. # move to new location, keep name
$ python
>>> print( 2 * 3 + 0.3 )
$ python script.py
$ cat script.py
print( 2 * 3 + 0.3 )
import os # e.g. for os.path.isdir
import sys # e.g. for reading arguments
import numpy as np # numerical python
import matplotlib.pyplot as plt # submodule for nice plots
x = 2.0 # declared and value assigned
y = 3.0
print( x + y ) # sum
a = "hello "
b = "world"
print( a + b ) # concat
print( a[1:5] ) # substring
l = [ 1, 3.4, "alpha"]
print( l )
print( l[2] )
l.append( 3.2 )
print( l[-1] )
print( l[0:2] )
l = [0,"day", ["x","@" ] ]
print( l[2][1] )
d = {}
d["beer"] = 3.50
d["hot dog"] = 2.99
print( d )
print("total: ", 2*d["beer"] + d["hot dog"] )
print( "how extraordinary!", x )
with open( 'file.txt', 'r' ) as f:
for l in f:
words = l.split()
with open( 'file.txt', 'w' ) as w:
w.write( "x: " + str(x) + "\n")
print( x , file=w )
with open( 'file.txt', 'w' ) as w:
w.write( "x: " + str(x) + "\n")
print( x , file=w )
if True:
a = "cheers"
print( a) # a is not known, ERROR
a = ""
if True:
a = "cheers"
print( a) # a is known, has value "cheers"
sum = 0
for x in [ 1 , 2 , 3 ]:
sum += x
print( "total:", sum)
count = 0
while count < 100:
print( "trallalla" )
count += 1
with open( 'protein.pdb' ) as f:
for l in f:
if "ATOM" in l:
x = float( l[30:38] ) # convert string to number
y = float( l[38:46] )
z = float( l[46:54] )
types = [ 'CA', 'N', 'C' , 'O' ] # protein backbone
with open( 'protein.pdb' ) as f:
for l in f:
atom_type = l[12:16].strip()
if "ATOM" in l and atom_type in types:
print( l )