Skip to content

Instantly share code, notes, and snippets.

@arraytools
arraytools / 0-readme.txt
Last active April 9, 2025 02:23
R shiny application with non-root output. Go to http://localhost:3838/myapp to see the shiny application.
$ tree
├── app
│ └── myapp
│ └── app.R
└── compose.yml
$ mkdir -p app/myapp
$ sudo chmod 777 app/myapp # shiny user can write
$ docker compose up
# Click the 'Write Output File' button
@arraytools
arraytools / test.nwt
Last active March 12, 2025 17:49
causative.nwt for testing
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<sbgn xmlns="http://sbgn.org/libsbgn/0.3">
<map id="causative.nwt" language="sif">
<extension>
<renderInformation
xmlns="http://www.sbml.org/sbml/level3/version1/render/version1" id="renderInformation" program-name="sbgnviz" program-version="6.0.1" background-color="#00000000">
<listOfColorDefinitions>
<colorDefinition id="color_1" value="#ffffffff"/>
<colorDefinition id="color_2" value="#323232"/>
<colorDefinition id="color_3" value="#ff8164"/>
1. The Elevator Pitch Summary
Prompt: "Summarise this paper in 3–5 sentences, as if you're explaining it to a colleague in an elevator ride."
2. Key Findings Extraction
Prompt: "List the top 5 key findings or conclusions from this paper, along with a brief explanation of each."
3. Methodology Breakdown
Prompt: "Explain the methodology used in this study in simple terms. What are its strengths and potential limitations?"
4. Literature Review Assistant
@arraytools
arraytools / R-options.R
Last active February 16, 2025 01:48
Beyond Function Parameters: Using R Options for Dynamic Inputs. Demonstrate the idea behind the post "Using options() to inject a function’s internal variable for reproducible testing" https://brodrigues.co/posts/2025-02-13-testthat.html
calculate_total <- function(items) {
subtotal <- sum(items)
tax_rate <- getOption("TAX_RATE", default = 0.1) # Default 10% tax
total <- subtotal * (1 + tax_rate)
return(round(total, 2))
}
# Test the function with default tax rate
cart1 <- c(10, 20, 30)
print(calculate_total(cart1)) # Output: 66.00
@arraytools
arraytools / bitbucket.py
Created February 9, 2025 20:15
Return the name and the size of each bitbucket repositories. Step 1: Change username and app_password, Step 2: Run "python3 bitbucket_download.py". The app_password can be created from Avatar -> Personal settings from the dropdown menu on RHS. Navigate to App Passwords and then Access management -> App passwords.
import requests
from requests.auth import HTTPBasicAuth
username = "USERNAME"
app_password = "API_PASSWORD"
base_url = f"https://api.bitbucket.org/2.0/repositories/{username}"
def fetch_repositories(url):
response = requests.get(url, auth=HTTPBasicAuth(username, app_password))
response.raise_for_status() # Raises an error for bad status codes
@arraytools
arraytools / shiny_rainbow.R
Created January 2, 2025 21:31
A Shiny app to understand the `saturation` and `value` parameters in the rainbow() function
library(shiny)
# Define the UI
ui <- fluidPage(
titlePanel("Rainbow Color Palette"),
sidebarLayout(
sidebarPanel(
sliderInput("s_value", "Saturation (s):", min = 0, max = 1, value = 1, step = 0.01),
sliderInput("v_value", "Value (v):", min = 0, max = 1, value = 1, step = 0.01)
),
@arraytools
arraytools / simulation_logrank_test.R
Created December 2, 2024 21:55
Compare the effects of sample size on the log-rank test
library(survival)
# Function to generate survival data
generate_data <- function(sample_size, event_rate_group1, event_rate_group2) {
group <- c(rep(1, sample_size), rep(0, sample_size))
event_times <- c(rexp(sample_size, rate = event_rate_group1),
rexp(sample_size, rate = event_rate_group2))
observed <- rep(1, sample_size * 2) # Assuming all events are observed
data <- data.frame(group = group, event_times = event_times, observed = observed)
return(data)
@arraytools
arraytools / Singularity
Last active April 20, 2024 12:05
Corrected singularity definition file for RNA-Seq analysis. The original file is available from https://hpc.nih.gov/apps/singularity.html. Especially, From: is changed to use miniconda3. I have to comment out sailfish installation.
sudo singularity build rnaseq3 rnaseq3.def
./rnaseq3 cat /etc/os-release # debian 11, host=ubuntu 2204
./rnaseq3 samtools --version # 1.10
./rnaseq3 STAR --version # 2.5.2b
./rnaseq3 fastqc -v # v0.12.1
./rnaseq3 kallisto | head 1 # 0.50.1
./rnaseq3 subread # command not found
./rnaseq3 featureCounts -v | head # v2.0.6
./rnaseq3 ls /opt/conda/bin
./rnaseq3 which gcc # 10.2.1
@arraytools
arraytools / TCGAbiolinks-GBM.Rmd
Last active March 11, 2024 00:27
This is an updated/enhanced version of [TCGAbiolinks to DESEq2](https://rpubs.com/tiagochst/TCGAbiolinks_to_DESEq2)
-3.2510638297872343 -231.0344827586207
-2.2808510638297874 -170.68965517241372
-2.612765957446809 -151.72413793103442
3.1063829787234054 246.55172413793102
3.846808510638298 246.55172413793102
2.7234042553191484 175.86206896551727
2.340425531914893 194.82758620689657
2.519148936170212 158.62068965517244
2.187234042553192 162.0689655172414
2.187234042553192 146.55172413793105