Skip to content
Snippets Groups Projects
Commit 1c13bb3b authored by Vermaat's avatar Vermaat
Browse files

Remove obsolete lessons

parent 9920b5b9
No related branches found
No related tags found
No related merge requests found
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<span style=\"font-size: 200%\">Version control with Git</span>\n",
"===\n",
"\n",
"<br>\n",
"\n",
"[Zuotian Tatum](mailto:z.tatum@lumc.nl), [Martijn Vermaat](mailto:m.vermaat.hg@lumc.nl)\n",
"\n",
"[Department of Human Genetics, Leiden University Medical Center](http://humgen.nl)\n",
"\n",
"License: [Creative Commons Attribution 3.0 License (CC-by)](http://creativecommons.org/licenses/by/3.0)\n",
"\n",
"Sources: [Git homepage](http://git-scm.com/), [GitHub Teaching](https://teach.github.com/), [Try Git](http://try.github.io/)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%html\n",
"<style type=\"text/css\">\n",
"/* Remove the vertical scrollbar added by nbconvert. */\n",
".reveal {\n",
" overflow-y: hidden;\n",
"}\n",
"</style>"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "skip"
}
},
"outputs": [
{
"html": [
"<style type=\"text/css\">\n",
"/* Remove the vertical scrollbar added by nbconvert. */\n",
".reveal {\n",
" overflow-y: hidden;\n",
"}\n",
"</style>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.HTML at 0x1f571d0>"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"What is a Version Control System (VCS)\n",
"===\n",
"\n",
"> *Revision control*, also known as version control and source control (and an aspect of software configuration management), is the management of changes to documents, computer programs, large web sites, and other collections of information. --- [Wikipedia](http://en.wikipedia.org/wiki/Revision_control)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Why VCS\n",
"===\n",
"\n",
"For a single user:\n",
"---\n",
"* revert files to a previous state\n",
"* revert the entire project back to a previous state\n",
"* review changes made over time\n",
"* backup\n",
"* ...\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"For multiple users:\n",
"---\n",
"* a reliable way to share files between people/computers\n",
"* allow multiple people working on the same project at the same time\n",
"* conflict resolution\n",
"* see who made what changes at when\n",
"* ..."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"VCS architecture\n",
"===\n",
"\n",
"Local VCS\n",
"---\n",
"\n",
"<img src=\"files/images/local_vcs.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"VCS architecture\n",
"===\n",
"\n",
"Centralized VCS\n",
"---\n",
"<img src=\"files/images/centralized_vcs.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"VCS architecture\n",
"===\n",
"\n",
"Distributed VCS\n",
"---\n",
"<img src=\"files/images/distributed_vcs.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Git\n",
"===\n",
"\n",
"\n",
"A distributed version control system.\n"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"git"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n",
" [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n",
" [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n",
" [-c name=value] [--help]\n",
" <command> [<args>]\n",
"\n",
"The most commonly used git commands are:\n",
" add Add file contents to the index\n",
" bisect Find by binary search the change that introduced a bug\n",
" branch List, create, or delete branches\n",
" checkout Checkout a branch or paths to the working tree\n",
" clone Clone a repository into a new directory\n",
" commit Record changes to the repository\n",
" diff Show changes between commits, commit and working tree, etc\n",
" fetch Download objects and refs from another repository\n",
" grep Print lines matching a pattern\n",
" init Create an empty git repository or reinitialize an existing one\n",
" log Show commit logs\n",
" merge Join two or more development histories together\n",
" mv Move or rename a file, a directory, or a symlink\n",
" pull Fetch from and merge with another repository or a local branch\n",
" push Update remote refs along with associated objects\n",
" rebase Forward-port local commits to the updated upstream head\n",
" reset Reset current HEAD to the specified state\n",
" rm Remove files from the working tree and from the index\n",
" show Show various types of objects\n",
" status Show the working tree status\n",
" tag Create, list, delete or verify a tag object signed with GPG\n",
"\n",
"See 'git help <command>' for more information on a specific command.\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"Configuration\n",
"---"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's add some information about you."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh \n",
"git config --global user.name \"Z. Tatum\"\n",
"git config --global user.email \"z.tatum@lumc.nl\""
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"Initialize a Git repository\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"cd /tmp/myproject"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"/tmp/myproject\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git init"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Initialized empty Git repository in /tmp/myproject/.git/\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"ls -al"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"total 20\n",
"drwxr-xr-x 3 ztatum ztatum 4096 Aug 5 17:18 .\n",
"drwxrwxrwt 14 root root 12288 Aug 5 17:18 ..\n",
"drwxr-xr-x 7 ztatum ztatum 4096 Aug 5 17:18 .git\n"
]
}
],
"prompt_number": 5
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"Check repository status\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git status"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"# On branch master\n",
"#\n",
"# Initial commit\n",
"#\n",
"nothing to commit (create/copy files and use \"git add\" to track)\n"
]
}
],
"prompt_number": 6
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"Track changes\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"echo \"This is a simple test repository\" > README"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh \n",
"\n",
"git status"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"# On branch master\n",
"#\n",
"# Initial commit\n",
"#\n",
"# Untracked files:\n",
"# (use \"git add <file>...\" to include in what will be committed)\n",
"#\n",
"#\tREADME\n",
"nothing added to commit but untracked files present (use \"git add\" to track)\n"
]
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"Stage changes\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git add README\n",
"git status"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"# On branch master\n",
"#\n",
"# Initial commit\n",
"#\n",
"# Changes to be committed:\n",
"# (use \"git rm --cached <file>...\" to unstage)\n",
"#\n",
"#\tnew file: README\n",
"#\n"
]
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git\n",
"===\n",
"\n",
"Commit changes\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git commit -m \"add README to repository\""
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[master (root-commit) 0e137b0] add README to repository\n",
" 1 file changed, 1 insertion(+)\n",
" create mode 100644 README\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"Staging\n",
"---\n",
"\n",
"<img src=\"http://git-scm.com/images/about/index1@2x.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - bascis\n",
"===\n",
"\n",
"Staging (skipped)\n",
"---\n",
"<img src=\"http://git-scm.com/images/about/index2@2x.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git\n",
"===\n",
"\n",
"Commit multiple files\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh \n",
"\n",
"touch file1.txt file2.txt\n",
"git add *.txt\n",
"git status"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"# On branch master\n",
"# Changes to be committed:\n",
"# (use \"git reset HEAD <file>...\" to unstage)\n",
"#\n",
"#\tnew file: file1.txt\n",
"#\tnew file: file2.txt\n",
"#\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git commit -m \"add more files to repo\""
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[master 56fe8bf] add more files to repo\n",
" 0 files changed\n",
" create mode 100644 file1.txt\n",
" create mode 100644 file2.txt\n"
]
}
],
"prompt_number": 12
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git\n",
"===\n",
"\n",
"History\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git log"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\u001b[33m5c68824\u001b[m -\u001b[31m (HEAD, master)\u001b[m add more files to repo \u001b[32m(4 seconds ago) \u001b[1;34m<Z. Tatum>\u001b[m\n",
"\u001b[33mbd4898f\u001b[m -\u001b[31m\u001b[m add README to repository \u001b[32m(12 seconds ago) \u001b[1;34m<Z. Tatum>\u001b[m"
]
}
],
"prompt_number": 12
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git log --summary"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\u001b[33m5c68824\u001b[m -\u001b[31m (HEAD, master)\u001b[m add more files to repo \u001b[32m(6 seconds ago) \u001b[1;34m<Z. Tatum>\u001b[m\n",
" create mode 100644 file1.txt\n",
" create mode 100644 file2.txt\n",
"\n",
"\u001b[33mbd4898f\u001b[m -\u001b[31m\u001b[m add README to repository \u001b[32m(14 seconds ago) \u001b[1;34m<Z. Tatum>\u001b[m\n",
" create mode 100644 README\n"
]
}
],
"prompt_number": 13
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"What have I changed?\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"echo \"This repo is getting interesting\" >> README\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's ask git what are the changes in README."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git diff README"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"diff --git a/README b/README\n",
"index 323f517..bf576e7 100644\n",
"--- a/README\n",
"+++ b/README\n",
"@@ -1 +1,2 @@\n",
" This is a simple test repository\n",
"+This repo is getting interesting\n"
]
}
],
"prompt_number": 15
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"work, commit, work, commit, ...\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git add README\n",
"git commit -m \"Update README with interesting stuff.\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[master 33a1231] Update README with interesting stuff.\n",
" 1 file changed, 1 insertion(+)\n"
]
}
],
"prompt_number": 16
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"Rename files\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git mv file1.txt file_boring.txt\n",
"git status"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"# On branch master\n",
"# Changes to be committed:\n",
"# (use \"git reset HEAD <file>...\" to unstage)\n",
"#\n",
"#\trenamed: file1.txt -> file_boring.txt\n",
"#\n"
]
}
],
"prompt_number": 17
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"Rmoving files\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git rm file2.txt\n",
"git status"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"rm 'file2.txt'\n",
"# On branch master\n",
"# Changes to be committed:\n",
"# (use \"git reset HEAD <file>...\" to unstage)\n",
"#\n",
"#\tdeleted: file2.txt\n",
"#\trenamed: file1.txt -> file_boring.txt\n",
"#\n"
]
}
],
"prompt_number": 18
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git commit -m \"renaming and removing files\""
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[master 1cf2126] renaming and removing files\n",
" 1 file changed, 0 insertions(+), 0 deletions(-)\n",
" delete mode 100644 file2.txt\n",
" rename file1.txt => file_boring.txt (100%)\n"
]
}
],
"prompt_number": 19
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"$\\S$ Exercise: git basics\n",
"===\n",
"\n",
"* add a new file *file_exciting.txt*\n",
"* commit it\n",
"* make some exciting changes to it\n",
"* commit it again\n",
"* remove it\n",
"* commit it one last time"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"revert changes\n",
"---\n"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"echo \"this is the wrong file\" >> wrong.txt\n",
"git add wrong.txt"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 13
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"Reset is the opposite of add. It removes a staged file from the staging area."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"git reset wrong.txt\n",
"git status"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"# On branch master\n",
"# Untracked files:\n",
"# (use \"git add <file>...\" to include in what will be committed)\n",
"#\n",
"#\twrong.txt\n",
"nothing added to commit but untracked files present (use \"git add\" to track)\n"
]
}
],
"prompt_number": 16
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - basics\n",
"===\n",
"\n",
"Revert commit\n",
"---"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"echo \"this is the wrong file\" >> wrong.txt\n",
"git add wrong.txt\n",
"git commit -m \"this is a bad commit\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"[master 1e85daa] this is a bad commit\n",
" 1 file changed, 6 insertions(+)\n",
" create mode 100644 wrong.txt\n"
]
}
],
"prompt_number": 22
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git reset HEAD^\n",
"git status"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"# On branch master\n",
"# Untracked files:\n",
"# (use \"git add <file>...\" to include in what will be committed)\n",
"#\n",
"#\twrong.txt\n",
"nothing added to commit but untracked files present (use \"git add\" to track)\n"
]
}
],
"prompt_number": 23
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git log "
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\u001b[33m56fe8bf\u001b[m -\u001b[31m (HEAD, master)\u001b[m add more files to repo \u001b[32m(38 minutes ago) \u001b[1;34m<Z. Tatum>\u001b[m\n",
"\u001b[33m0e137b0\u001b[m -\u001b[31m\u001b[m add README to repository \u001b[32m(39 minutes ago) \u001b[1;34m<Z. Tatum>\u001b[m"
]
}
],
"prompt_number": 24
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Git - Basics workflow\n",
"===\n",
"\n",
"<div style=\"text-align:center\"><img src=\"files/images/git-local.png\" width=\"500\"></div>"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Git - Remote workflow\n",
"===\n",
"\n",
"<div style=\"text-align:center\"><img src=\"files/images/git-remote.png\" width=\"700\"></div>"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Git - remote repository\n",
"===\n",
"\n",
"**A remote repository**: a pointer to another copy of the repository that lives on a different location. This can be simply a different path on the filesystem or a server on the internet.\n",
"\n",
"A popular example of git remote server: [github.com](https://github.com)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"But for this course, we use GitLab at LUMC. **https://git.lumc.nl **\n",
"\n",
"\n",
"<img src='files/images/gitlab_screenshot.png'>"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - remote repository\n",
"===\n",
"\n",
"Create a repository on a remote server\n",
"---\n",
"\n",
"* create a new project\n",
"* **fork** an existing project"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - remote repository\n",
"===\n",
"\n",
"Create a new project\n",
"---\n",
"\n",
"<img src=\"files/images/gitlab_create_project.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - remote repository\n",
"===\n",
"\n",
"Create a new project\n",
"---\n",
"\n",
"<img src=\"files/images/gitlab_new_project.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - remote repository\n",
"===\n",
"\n",
"Create a new project\n",
"---\n",
"\n",
"Now let's add the remote repository."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git remote add origin git@git.lumc.nl:z.tatum/myproject.git"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"outputs": [],
"prompt_number": 26
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh \n",
"\n",
"git push -u origin master"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Branch master set up to track remote branch master from origin.\n"
]
},
{
"output_type": "stream",
"stream": "stderr",
"text": [
"To git@git.lumc.nl:z.tatum/myproject.git\n",
" * [new branch] master -> master\n"
]
}
],
"prompt_number": 27
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git pull"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Already up-to-date.\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - remote repository\n",
"===\n",
"\n",
"Fork a project\n",
"---\n",
"\n",
"* Fork the course-assignments repository on gitlab\n",
"* Clone **your** course-assignments repository to your laptop\n"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git clone git@git.lumc.nl:z.tatum/course-assignments.git\n",
" \n",
"cd course-assignments"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"** For the rest of the class, you are going to use this repository to track and submit your assignements.**"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"$\\S$ Exercise: git remote\n",
"===\n",
"\n",
"* copy the python files you created yesterday\n",
"* add them to your course-assignment repository\n",
"* push them to the remote server (you can check it on the gitlab website)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Git - branching\n",
"===\n",
"\n",
"What is a branch?\n",
"---\n",
"\n",
"<img src=\"files/images/git-branching.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - branching\n",
"===\n",
"\n",
"Why branching?\n",
"---\n",
"\n",
"* a playground to try out new ideas.\n",
"* a place stablize a feature.\n",
"* unconventional usages (documenation, git-annex, etc.)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - branching\n",
"===\n",
"\n",
"Master branch\n",
"---\n",
"\n",
"We are already working in a branch called **master**."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git branch -v"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"* master 56fe8bf add more files to repo\n"
]
}
],
"prompt_number": 25
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Git - branching\n",
"===\n",
"\n",
"Working with a branch\n",
"---\n"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git branch new_experiment"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git checkout new_experiment"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"source": [
"work, commit, work, commit, work..."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%sh\n",
"\n",
"git checkout master\n",
"git merge new_experiment"
],
"language": "python",
"metadata": {
"slideshow": {
"slide_type": "fragment"
}
},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"Futher reading\n",
"===\n",
"\n",
"* [Git Book](http://git-scm.com/book/en/)\n",
" <br>\n",
" from the official git web site.\n",
"\n",
"* [Github teach](https://teach.github.com/)\n",
" <br>\n",
" GitHub Official Teaching Materials\n",
"\n",
"* just search \"git tutorial\"\n",
" <br>\n",
" i.e. [top ten git tutorials for beginners](http://sixrevisions.com/resources/git-tutorials-beginners/)"
]
}
],
"metadata": {}
}
]
}
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
#!/usr/bin/env python
import random
class Sequence(object):
bases = ['A', 'C', 'G', 'T']
def __init__(self, spots, readlength=100):
self.cycle = 0
self.readlength = readlength
self.spots = spots
def __iter__(self):
return self
def __len__(self):
return self.readlength
def next(self):
self.cycle += 1
if self.cycle > self.readlength:
raise StopIteration
tile = []
for _ in range(self.spots):
nucleotide = self.bases[random.randrange(4)]
quality = 40 - (self.cycle * random.randrange(40) /
self.readlength)
tile.append((nucleotide, quality))
return tile
class Read(object):
def __init__(self):
self.read = []
self.qual = []
def __str__(self):
return "".join(self.read)
def append(self, base):
self.read.append(base[0])
self.qual.append(base[1])
def quality(self):
return sum(self.qual) / len(self.read)
def trim(self, score):
for position in range(len(self.read) - 1, -1, -1):
if self.qual[position] >= score:
self.read = self.read[:position + 1]
self.qual = self.qual[:position + 1]
break
def with_class():
spots = 2
run = Sequence(spots)
reads = [Read() for _ in range(spots)]
for tile in run:
for read_id, base in enumerate(tile):
reads[read_id].append(base)
for i in reads:
print i, i.quality()
i.trim(39)
print i, i.quality()
def quality(quals):
return sum(quals) / len(quals)
def trim(read, quals, score):
for position in range(len(read) - 1, 0, -1):
if quals[position] >= score:
return read[:position + 1], quals[:position + 1]
def without_class():
spots = 2
run = Sequence(spots)
reads = ["" for _ in range(spots)]
quals = [[] for _ in range(spots)]
for tile in run:
for read_id, base in enumerate(tile):
reads[read_id] += base[0]
quals[read_id].append(base[1])
for read_id, read in enumerate(reads):
print read, quality(quals[read_id])
read, quals[read_id] = trim(read, quals[read_id], 39)
print read, quality(quals[read_id])
if __name__ == "__main__":
#without_class()
with_class()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment