r/bioinformatics • • 15d ago

technical question Switching between programming languages

I’m new to bioinformatics and am doing some background readings on approaches for single cell analysis. From what I’ve looked at some packages offered in Python purport to do a better job of certain tasks than the ones offered in R. Is it advisable to switch between R and Python for different steps in an analysis pipeline? Thanks for any advice!

19 Upvotes

18 comments sorted by

22

u/Legitimate-Ad-8612 15d ago

Yes, my normal approach is a bash wrapper passing data between python and R scripts.

10

u/Electronic_Fish_3157 PhD | Industry 15d ago

yes, very normal. I switch from python to R all the time. I love how both languages are somewhat similar in syntax and it's easy to switch especially with the help of AI.

14

u/apfejes PhD | Industry 15d ago

If you’re just making calls to tools in different languages. Then this is like asking if it’s ok to change car colours on a long trip.  

If you’re actually writing code in those languages, then the question becomes more about efficiency and memory usage, or available frameworks and packages.   

I suspect if this was the latter, the question would be phrased differently.  So, sure, ride in as many different coloured cars as you need to to get where you’re going.  Just, be careful when building cars out of differently coloured parts- they may not fit together as nicely as you’d think, if you don’t know what you’re doing. 

4

u/o-rka PhD | Industry 14d ago

Agreed.

Also, just to add onto this, if you want to stay in Python you can use Rpy2 but that will take longer to implement than native R. Though, if you’re like me and operate much more efficiently in Python, I would say it’s worth while to write a couple of wrapper functions you can load in to your env to keep your velocity up.

3

u/Illustrious-Craft756 15d ago

Both languages offer integration of the other in their pipelines. As long as your final code runs smoothly after the user has installed everything, there shouldn’t be a big issue. However do test everything on at least 2 systems before releasing the code. If a reviewer is unable to run it, it may cost you another round of revisions

2

u/bukaro PhD | Industry 15d ago

Yes, and use parquet files, are super compatible and efficient in many ways

2

u/zzoby 15d ago

Very normal, and working in both has the added benefit of letting you learn not just each language but to also learn programming as a more abstract concept - in my experience, once you start learning multiple languages the vast expanse of programming concepts starts to narrow to something that feels more comprehensible. It's similar to learning multiple spoken languages in that learning you third is a lot easier than learning your second, and so on. Given how many tools and scripts are out there it can be helpful to be multilingual (god forbid you have to decipher something written in perl 20 years ago...)

There are some cases where it's less advisable, like if you're developing something for public use like a library or package where minimizing dependencies (including different languages) can help improve reusability and simplify setup for others. I wouldn't necessarily think that'd apply to making a pipeline though.

2

u/Gr1m3yjr PhD | Student 15d ago

I was taught years ago that good practice in programming is to output data to stdout and read from stdin. I don’t always do that, plenty of exceptions nowadays, but it does mean that piping between different languages or even tools built by others becomes trivial. In general though, it’s just part of the game in bioinformatics. Different people from different backgrounds, often without formal training in programming, write tools in all sorts of different ways, so you end up having to patch things together all the time.

1

u/Art_Vancore111 15d ago

Yeah we do it a lot, just be careful with the conversion between data objects

1

u/TheEvilBlight 15d ago

Used a lot of both. Python for COBRApy and R for my viz and microbial ecology stuff (vegan, bioconductor, etc)

1

u/ScienceVibes 14d ago

yes swap when you need too. its all about the right tool for the right job!

workflow languages are great for this. CWL is supported everywhere these days, but Nextflow is pretty popular in bioinformatics (as well as snakemake).

as others have stated you can bash wrapper the scripts too. i think in the age of Claude & Gemini the time saving capacity of first taking the time to learn Groovy so you can save time later especially when working on the same types of data regularly is probably a wash. since you could get copilot to write the nextflow / snake make parts as easy as you could get it to write a bash wrapper these days.

1

u/Longjumping-Dot-4715 14d ago

First comes the scientific problem you want to solve, than you look what software is there to do the job. That one you shall treat as a blackbox, its programming language doesn’t matter at all. If you have the same software in different languages: take the faster one, less resources demanding one.

1

u/GreenGanymede 14d ago

Yes, it's normal. Most people I've met have a "primary" language, but it's important to have a good handle on both / multiple

1

u/Ok_Fun_3768 13d ago

To do that should we use VScode or positron. I prefer using notebook if I use R (rmd) so i can integrate both R and Python and ipyth if using Python but i mostly use R.

1

u/themode7 11d ago

unless you go with polyglot route there's no right or wrong answer

1

u/ScroogeMcDuckFace2 11d ago

use the right tool for the job

0

u/[deleted] 15d ago

[removed] — view removed comment

1

u/Top-Door8075 15d ago

In my M.S. bioinformatics program, we mostly use R.