Skip to content

Commit 8876e5c

Browse files
committed
2 parents dcebc0a + 8779135 commit 8876e5c

26 files changed

Lines changed: 550 additions & 550 deletions

IntroToPython/inst/extdata/Descriptions/Session2Overview.Rmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ The session includes longer exercises and shorter slide decks and so more time s
77

88
Session sections:
99

10-
* Looping Conditional Branching
1110
* Loading libraries
1211
* Writing Scripts
1312
* Getting help
File renamed without changes.

IntroToPython/inst/extdata/data/susbet_dataset_args.py renamed to IntroToPython/inst/extdata/data/subset_dataset_args.py

File renamed without changes.

IntroToPython/inst/extdata/presRaw/Session1.Rmd

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,13 @@ Guido van Rossum began working on Python in the late 1980s as a successor to the
9191

9292
One of the most noticeable differences comes from the emphasis on code readability:
9393

94-
it uses significant indentation
94+
<div style="text-indent: 2em;">
95+
it uses significant indentation.
96+
</div>
9597

9698
Python 3.0, released in 2008, was a major revision not completely backward-compatible with earlier versions. Python 2.7 and older is officially unsupported but some tools require it.
9799

98-
<img src="imgs/Python.png" alt="python" height="300" width="300">
100+
<img src="imgs/Python.png" alt="python" height="250" width="250">
99101

100102
---
101103
## What is Python to you?
@@ -241,15 +243,7 @@ conda install jupyter
241243
```
242244

243245

244-
---
245-
## Interactive or scripts?
246-
247-
As with many languages you can work with python in two main ways:
248-
interactive or scripts.
249-
250-
When people think about coding they are often thinking about the interactive **console**. This is what we saw earlier when we first opened python. When you work in this way lines of code are submitted as you enter them. You often do this when you are developing an analysis and trying out parameters. This is mostly how we will work in the training.
251246

252-
When you want to automate something, i.e. an analysis workflow, you will write a script. You can then run this script with python and it will run every line of code for you sequentially.
253247

254248
---
255249
## Python and IDEs
@@ -318,6 +312,31 @@ Once the Terminal is open, you can then just open Python, by typing `python` int
318312

319313
There is is an easier shortcut to do this. Once you start developing code the easiest way to open it is to use the `Shift + Enter` shortcut.
320314

315+
---
316+
## Why VS code and IDEs
317+
318+
As VS code is an IDE it allows us to access and run python. But also do several other things from the same portal i.e.
319+
320+
- Explore files
321+
- Open/Write scripts
322+
- Shortcuts for common python utilities
323+
- Have a live plotting window
324+
- GitHub integration
325+
- Advanced coding features for debugging and LLM support
326+
327+
We won't full dive into everything but getting familiar early is best.
328+
329+
---
330+
## Interactive or scripts?
331+
332+
As with many languages you can work with python in two main ways:
333+
interactive or scripts.
334+
335+
When people think about coding they are often thinking about the interactive **console**. This is what we saw earlier when we first opened python. When you work in this way lines of code are submitted as you enter them. You often do this when you are developing an analysis and trying out parameters. This is mostly how we will work in the training.
336+
337+
When you want to automate something, i.e. an analysis workflow, you will write a script. You can then run this script with python and it will run every line of code for you sequentially.
338+
339+
321340
---
322341
## Quick Recap
323342

@@ -523,6 +542,22 @@ except Exception as e:
523542
524543
```
525544

545+
---
546+
## A quick aside
547+
548+
You will run into errors coding.
549+
550+
DON'T PANIC.
551+
552+
Most of the time the error messages are very clear. And if they are not a quick google will often clear it up.
553+
554+
In this case we can break it down:
555+
556+
* ValueError - The content is invalid for the operation. The first statement is the overarching name for the error.
557+
* invalid literal for int() - Specifically the int() function is expecting something different
558+
* with base 10 - It is expecting base 10 numbers/integers
559+
* 'Hello!' - This is what you gave it. We can see it doesn't match the criteria above.
560+
526561
---
527562
## Concatenation
528563

@@ -837,14 +872,7 @@ except Exception as e:
837872
838873
```
839874

840-
---
841-
## A quick aside
842-
843-
You will run into errors coding.
844875

845-
DON'T PANIC.
846-
847-
Most of the time the error messages are very clear. And if they are not a quick google will often clear it up.
848876

849877
---
850878
## Tuple/List coercion
@@ -1228,7 +1256,7 @@ arr
12281256
---
12291257
## Adding Dimensions
12301258

1231-
It is possible to create many kinds of arrays, with differing dimensionality. They can be 1D,2D,3D etc. Typically we think about 2D arrays as this is often the rectangular data we deal with.
1259+
Typically we think about 2D arrays as this is often the rectangular data we deal with. It is possible to create many kinds of arrays, with differing dimensionality. They can be 1D,2D,3D etc.
12321260

12331261
Here we again create a list to coerce into a array. This time we have a list of lists. Each list will become equivalent to a row in our array.
12341262

@@ -1265,7 +1293,7 @@ arr_2d.reshape(9,1)
12651293
---
12661294
## Indexing Arrays
12671295

1268-
We can use same square brackets we used for other data objects to index our arrays. The big difference is we now have 2 dimensions. We therefore need to provide 2 indexes, separated by a comma.
1296+
We can use the same square brackets we used for other data objects to index our arrays. The big difference is we now have 2 dimensions. We therefore need to provide 2 indexes, separated by a comma.
12691297

12701298
The first number will correspond to row. The second number will correspond to column.
12711299

@@ -1289,9 +1317,6 @@ arr_2d[0,1:3]
12891317
12901318
```
12911319

1292-
1293-
1294-
12951320
---
12961321
## Logical Indexing
12971322

@@ -1711,7 +1736,7 @@ There are several ways to control how your code is evaluated. There are two main
17111736

17121737
Conditional branching is the evaluation of a logical to determine whether a chunk of code is executed.
17131738

1714-
In Python, we use the if statement with the logical to be evaluated immediately after. The dependent code is indicated by a colon, new line and indentation.
1739+
In Python, we use the if statement with the logical to be evaluated immediately after. The dependent code is indicated by a **colon**, **new line** and **indentation**.
17151740

17161741
```{python}
17171742
@@ -1742,6 +1767,7 @@ if x > y:
17421767
print("The value of x is",x,"which is greater than", y)
17431768
17441769
```
1770+
17451771
The message is printed above because x is greater than y.
17461772

17471773

@@ -1874,7 +1900,7 @@ To help us write complex code we often use pseudocode as a starting point.
18741900
---
18751901
## Pseudocode
18761902

1877-
When we write pseudocode we are trying to write out each computational step in a human readaBle way.
1903+
When we write pseudocode we are trying to write out each computational step in a human readable way.
18781904

18791905
It is important to be specific, simple, concise and include the control structures that would be in your final code.
18801906

IntroToPython/inst/extdata/presRaw/Session2.Rmd

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,18 @@ os.chdir("/Users/mattpaul/Downloads/Intro_To_Python-master/r_course/")
203203
204204
```
205205

206-
Given that we started at: */Users/mattpaul*, we could have also used. This uses the knowledge that we are in that start position to find where we are going.
206+
This absolute pathway is very precise but it contains specific information about my computer. This means this will only work on this computer.
207+
208+
Given that we started at: */Users/mattpaul*, we could have also used a relative path. This uses the knowledge that we are in that start position to find where we are going.
207209

208210
```{python, eval=F}
209211
210212
os.chdir("Downloads/Intro_To_Python-master/r_course/")
211213
212214
```
213215

216+
If we ensure the code is run from an equivalent position, than we can use relative paths across computers.
217+
214218
---
215219
## Back to Reading
216220

@@ -290,11 +294,13 @@ sex
290294

291295

292296
---
293-
## Quick Recap
297+
## Quick Recap - Array Filtering
294298

295-
Once you have performed some analysis you will want to export it into a new file.
299+
Once you have performed some analysis you will want to export it into a new file.
296300

297-
Let's do some quick processing based on what we learned yesterday. First we will make a 2D array.
301+
Let's do some quick filtering of the data based on what we learned yesterday. We can then export the results later.
302+
303+
First we will make a 2D array.
298304

299305
```{python}
300306
@@ -337,7 +343,7 @@ np.savetxt("height-weight_female.csv", subset_array, delimiter=',', fmt='%s')
337343

338344
Though a lot of the time we may use these NumPy approaches, there are specific functions dedicated to a variety of data types.
339345

340-
The most common is [pandas](https://pandas.pydata.org/docs/getting_started/index.html#getting-started). This is a specialized library for managing data frames. It also has the ability to read/write from excel spreadsheets.
346+
The most common is [pandas](https://pandas.pydata.org/docs/getting_started/index.html#getting-started). This is a specialized library for managing data frames. These are similar to arrays but a little more flexible for multiple data types. It also has the ability to read/write from excel spreadsheets.
341347

342348
[BioPython](https://biopython.org/) and [BioNumPy](https://bionumpy.github.io/bionumpy/menu.html) have a range of utilities for managing biological data types i.e. fasta, fastq, etc.
343349

@@ -367,7 +373,7 @@ if(params$isSlides == "yes"){
367373

368374
## Scripts
369375

370-
So far we have been working interactively with the console: asking it questions and getting answers back immediately.
376+
So far we have predominately been working interactively with the console: asking it questions and getting answers back immediately.
371377

372378
When you want to run all your code, or if you want to start working on automation you can run a whole script instead. In this case we have all our code written out in a *.py document. This is good practice for matured analysis that you have finalized to ensure that you have everything properly documented.
373379

@@ -426,7 +432,7 @@ More traditionally we would invoke python directly and provide the script. You w
426432
```
427433
/Users/mattpaul/Deskt
428434
op/miniconda3/envs/intro_to_python/bin/python /Users/mattpaul/Documents/RU/Train
429-
ing/Intro_To_Python/r_course/data/susbet_dataset.py
435+
ing/Intro_To_Python/r_course/data/subset_dataset.py
430436
```
431437

432438

@@ -463,9 +469,7 @@ np.savetxt("data/height-weight_"+arg1+".csv", subset_array, delimiter=',', fmt='
463469
To pass the argument to our script when we run it, we simply add it after our python script.
464470

465471
```
466-
/Users/mattpaul/Deskt
467-
op/miniconda3/envs/intro_to_python/bin/python /Users/mattpaul/Documents/RU/Train
468-
ing/Intro_To_Python/r_course/data/susbet_dataset_args.py Male
472+
/Users/mattpaul/Desktop/miniconda3/envs/intro_to_python/bin/python /Users/mattpaul/Documents/RU/Training/Intro_To_Python/r_course/data/subset_dataset_args.py Male
469473
```
470474

471475
---

0 commit comments

Comments
 (0)