Skip to content

Commit

Permalink
W1
Browse files Browse the repository at this point in the history
  • Loading branch information
caalo committed Aug 7, 2024
1 parent 890307f commit f175756
Show file tree
Hide file tree
Showing 21 changed files with 293 additions and 356 deletions.
93 changes: 93 additions & 0 deletions 01-intro-to-computing.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
```{r, include = FALSE}
ottrpal::set_knitr_image_path()
```

# Intro to Computing

Welcome to Introduction to Python! Each week, we cover a chapter, which consists of a lesson and exercise. In our first week together, we will look at big conceptual themes in programming, see how code is run, and learn some basic grammar structures of programming.

## Goals of the course

In the next 6 weeks, we will explore:

- Fundamental concepts in high-level programming languages (Python, R, Julia, etc.) that is transferable: *How do programs run, and how do we solve problems using functions and data structures?*

- Beginning of data science fundamentals: *How do you translate your scientific question to a data wrangling problem and answer it?*

![Data science workflow. Image source: [R for Data Science](https://r4ds.hadley.nz/whole-game).](https://d33wubrfki0l68.cloudfront.net/571b056757d68e6df81a3e3853f54d3c76ad6efc/32d37/diagrams/data-science.png){width="450"}

- Find a nice balance between the two throughout the course: we will try to reproduce a figure from a scientific publication using new data.

## What is a computer program?

- A sequence of instructions to manipulate data for the computer to execute.

- A series of translations: English \<-\> Programming Code for Interpreter \<-\> Machine Code for Central Processing Unit (CPU)

We will focus on English \<-\> Programming Code for Python Interpreter in this class.

More importantly: **How we organize ideas \<-\> Instructing a computer to do something**.

## A programming language has following elements: {#a-programming-language-has-following-elements}

- Grammar structure to construct expressions

- Combining expressions to create more complex expressions

- Encapsulate complex expressions via **functions** to create modular and reusable tasks

- Encapsulate complex data via **data structures** to allow efficient manipulation of data

## Google Colab Setup

Google Colab is a Integrated Development Environment (IDE) on a web browser. Think about it as Microsoft Word to a plain text editor. It provides extra bells and whistles to using Python that is easier for the user.

Let's open up the KRAS analysis in Google Colab. If you are taking this course while it is in session, the project name is probably named "KRAS Demo" in your Google Classroom workspace. If you are taking this course on your own time, open up...

Today, we will pay close attention to:

- Python Console (Execution): Open it via View -\> Executed code history. You give it one line of Python code, and the console executes that single line of code; you give it a single piece of instruction, and it executes it for you.

- Notebook: in the central panel of the website, you will see Python code interspersed with word document text. This is called a Python Notebook (other similar services include Jupyter Notebook, iPython Notebook), which has chunks of plain text *and* Python code, and it helps us understand better the code we are writing.

- Variable Enviornment: Open it by clicking on the "{x}" button on the left-hand panel. Often, your code will store information in the Variable Environment, so that information can be reused. For instance, we often load in data and store it in the Variable Environment, and use it throughout rest of your Python code.

The first thing we will do is see the different ways we can run Python code. You can do the following:

1. Type something into the Python Console (Execution) and type enter, such as `2+2`. The Python Console will run it and give you an output.
2. Look through the Python Notebook, and when you see a chunk of Python Code, click the arrow button. It will copy the Python code chunk to the Python Console and run all of it. You will likely see variables created in the Variables panel as you load in and manipulate data.
3. Run every single Python code chunk via Runtime -\> Run all.

Remember that the *order* that you run your code matters in programming. Your final product would be the result of Option 3, in which you run every Python code chunk from start to finish. However, sometimes it is nice to try out smaller parts of your code via Options 1 or 2. But you will be at risk of running your code out of order!

To create your own content in the notebook, click on a section you want to insert content, and then click on "+ Code" or "+ Text" to add Python code or text, respectively.

Python Notebook is great for data science work, because:

- It encourages reproducible data analysis, when you run your analysis from start to finish.

- It encourages excellent documentation, as you can have code, output from code, and prose combined together.

- It is flexible to other programming languages, such as R.

###

Now, we will get to the basics of programming grammar.

## Grammar Structure 1: Evaluation of Expressions

- **Expressions** are be built out of **operations** or **functions**.

- Operations and functions take in **data types**, do something with them, and return another data type.

- We can combine multiple expressions together to form more complex expressions: an expression can have other expressions nested inside it.

For instance, consider the following expressions entered to the Python Console:

```{python}
18 + 21
max(18, 21)
max(18 + 21, 65)
18 + (21 + 65)
len("ATCG")
```
23 changes: 0 additions & 23 deletions 01-intro.Rmd

This file was deleted.

261 changes: 0 additions & 261 deletions 02-chapter_of_course.Rmd

This file was deleted.

5 changes: 2 additions & 3 deletions _bookdown.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
book_filename: "Course_Name"
book_filename: "Introduction to Python"
chapter_name: "Chapter "
repo: https://github.com/jhudsl/OTTR_Template/
rmd_files: ["index.Rmd",
"01-intro.Rmd",
"02-chapter_of_course.Rmd",
"01-intro-to-computing.Rmd",
"About.Rmd",
"References.Rmd"]
new_session: yes
Expand Down
Loading

0 comments on commit f175756

Please sign in to comment.