Skip to content

Programming Languages

magnesium2400 edited this page Apr 4, 2023 · 2 revisions

We suggest becoming proficient in the same language as your direct supervisor (start by choosing 1 language)

Python MATLAB R
I’m stuck. I don’t know what to choose! In general, we suggest asking your supervisor what they use and start there. However, here are some other things to consider:
  • Python is extremely commonly used. If you see yourself as a hobbyist and like to run personal projects, it is great to learn Python. If you want any kind of ‘tech’ career, Python is an absolute must (and JavaScript, C#, Ruby etc. though Python makes it easier to learn these). In neuroimaging, a lot of newer libraries are being written in Python.
  • MATLAB is the most ‘specialist’ of the languages, as it was designed for numerical computing and is mostly used in the science and engineering fields. In neuroimaging, a lot of the foundational libraries are written in Python.
  • If you are an honours student, you will need to use R for your coursework and so it might make sense to carry over what you learn for your data analysis and visualisations. It’s more specific than Python, as it has a strong focus on statistical models and wrangling/visualising datasets. It is also used widely in industry and government because it’s free and simpler than Python. Most people really like RStudio (a graphical user interface (GUI) that is technically a separate entity from R) as well. Most people who used to use SPSS have now transitioned to R. R is the least commonly used in neuroimaging.
Principles and Philosophy Zen The strengths of MATLAB include extensive data handling and graphics capabilities, and advanced algorithms. This includes fast numerics for linear algebra, a large number of domain-specific built-in functions and libraries (e.g., for statistics, optimization, image processing, neural networks), easy generation of various kinds of visualisations of your data and/or simulation results. R for Data Science by Hadley Wickham

‘Just as a chemist learns how to clean test tubes and stock a lab, you’ll learn how to clean data and draw plots—and many other things besides. These are the skills that allow data science to happen, and here you will find the best practices for doing each of these things with R’.

Is it open-source Yes. Python is an open-source, general-purpose programming language run by a US not-for-profit called the ‘Python Software Foundation’. No. MATLAB is a language but it is also a proprietary computing environment (software). It is owned by Mathworks and Monash provides access to all staff and students. Octave, Scilab, and Julia are open-source alternatives, but are less popular. Yes. R and RStudio (a downloadable development environment/software that most people prefer to use when running R) are open source developed by some friendly kiwis :)
Getting Started
  1. Using Python on MASSIVE
  2. Option 2 - Download Python on your device
  3. 1st step - Download the language here
  4. 2nd step - choose your IDE (integrated development environment - software that you’ll use to interact with the code and run your code in). We recommend on of the following:
    • PyCharm - freely available here
    • Spyder - you can access through Anaconda - freely available here
  1. Option 1 - MASSIVE
    1. via GUI
      • Login to MASSIVE desktop
      • Go To Applications > General Scientific > MATLAB Alternatively
        1. via Desktop
          • Login to MASSIVE desktop
          • Open terminal
          • Type module load matlab/r2022b
          • Type matlab &
      • Option 2 - Download Matlab on your device
      • Available on the mathworks website using your Monash account. See the Monash Software Catalogue for more detailed instructions
      • You will need approx 4GB available
  1. Use RStudio on MASSIVE
  2. Download R and R Studio
    1. Download R-4.2.3 for Windows. The R-project for statistical computing.
    2. RStudio Desktop - Posit
  3. Use RStudio - R sits in the background without much influence
Introduction: Introduction to variables, loops, statements etc. Start with a simple self-paced course (intro to variables and if statements) ~1 hour.
  • This will give you a very brief introduction to python and programming

    Alternatively, try this intro to Python for data science course ~4 hours

    • This covers a bit more, including functions, and an intro to stats in python

      Introduction to plotting and data visualisation in Python via Matplotlib

      Most other plotting tools (including ones listed below) are built upon Matplotlib, so these are important fundamentals

      Or this more comprehensive course on python for neuroscience

      • This course does not include videos
      • It covers basics from variables and loops, to data manipulation and statistics.
      • It might be good to check it out to fill in the gaps in your knowledge
  1. Choose 1:
    1. Start with introductory materials from MathWorks ~1hr: Get Started
    2. Alternatively, Mathworks has the same content presented with videos ~1-2 hours
  2. For a more technical introduction, add on 1 of these:
    1. 1 hour YouTube course
    2. Long format MOOC from EPFL
For loops and if statements:

How to Use If-Else Statements and Loops in R – Dataquest

Functions

R - Functions

Intro to R:

An Introduction to R

1 Introduction | R for Data Science

Applications in neuroimaging
  1. Start here: Introduction to MRI in Python
  2. Choose the following as needed:
    1. dMRI analysis in Python
    2. fMRI analysis in Python
    3. sMRI analysis in Python
  3. Plotting neuroimaging data via nilearn.plotting, including plotting of:
    1. Volumetric data
    2. Surface data
    3. FC matrices
    4. fMRI carpet plots
  4. MRI preprocessing pipelines in Python (warning: more complex than previous resources)
  5. Gradient analyses in Python (also includes examples for loading and plotting fMRI data and FC)
  1. Our lab’s introductory tutorial to working with connectomes ~1 hour
  2. Network Based Statistic (Brain Connectivity Toolbox) for analysing all edges
  3. SPM for fMRI analysis
  4. Gradient analyses in MATLAB (also includes examples for loading and plotting fMRI data and FC)
R is not commonly used in neuroimaging contexts - but there are packages out there (e.g. ROBEX for ‘robust brain extraction’) built on R. Here is a good walk through on using some R packages for neuroimaging analyses:

Neuroimaging Analysis within R

However, there is also FSLR - a wrapper of FSL for R (it is more common for FSL to be used outside of R)

https://journal.r-project.org/articles/RJ-2015-013/RJ-2015-013.pdf

Otherwise - R is great for cleaning dataframes with psychological data (e.g. Likert scale based depression instrument data)

Learning statistics with R: A tutorial for psychology students and other beginners. (Version 0.6.1)

https://towardsdatascience.com/data-cleaning-in-r-made-simple-1b77303b0b17

For further reading as you develop your skills
Advanced techniques Machine Learning in Python
  • Semi-introductory course to Python with an emphasis on ML
MATLAB Programming Techniques

Numerical Computing

Undocumented tip and tricks

Beginner’s guide to machine learning in R (with step-by-step tutorial) | R-bloggers
Other notes Python Cheat Sheet
  • Basic guide that covers types of variables, lists, dicts, functions, numpy, matplotlib, etc
Blogs/Pick of the week

MATLAB on YouTube

8 R Programming Tips and Tricks That Will Make You More Efficient | by Adejumo Ridwan Suleiman | Level Up Coding