Skip to content

Instantly share code, notes, and snippets.

@TTTPOB
TTTPOB / shift_extend.py
Last active December 30, 2021 03:27
shift and extend paired end bam into a bed file
#!/usr/bin/env python3
import pysam
from collections import defaultdict
import subprocess
import click
from pathlib import Path
import pandas as pd
import numpy as np
from sys import stderr
@TTTPOB
TTTPOB / fastqdownload.smk
Last active November 14, 2021 06:07
download fastq from accession number and description from ena using ascp, fast and support md5 validation and retry when failed
# from fastq_downloader.helper import construct_gsm_dict, download_and_verify, rename_files_by_run, merge_files
from fastq_downloader.helper.construct_gsm_dict import infotsv_to_dict, parse_acc_type
from fastq_downloader.helper.download_and_verify import (
download_and_verify__,
check_file,
)
from fastq_downloader.helper.rename_files_by_run import (
write_filename_to_dict,
actual_rename,
)
@TTTPOB
TTTPOB / random_genomic_position.py
Created November 2, 2021 11:26
generate random genome position given chromosome_size.tsv
#!python3
import click
import random
def read_chrom_size(chrom_size):
chrom_size_dict = {}
with open(chrom_size) as f:
for line in f:
line = line.strip().split()
# save this script somewhere and invoke it in shell.nix shellHook
# it will read current r and radian path and write it to vscode
# workspace settings
# jq required
settings=.vscode/settings.json
mkdir -p .vscode
echo '{}' > $settings
rpath_exsits=$(cat $settings|jq '."r.rpath.linux"')
rterm_exsits=$(cat $settings|jq '."r.rterm.linux"')
not_exsist="null"
@TTTPOB
TTTPOB / shiftandmove_reference_for_computeMatrix.r
Created October 15, 2021 13:53
when using deeptools computeMatrix, you wont be able to get the central point "central", you need to shift the point half the binsize, and add a new bin
#!/usr/bin/env Rscript
suppressPackageStartupMessages({
library(tidyverse)
})
args <- commandArgs(trailingOnly = TRUE)
bed <- args[1]
distshift <- args[2] %>% as.numeric()
chromsize <- args[3]
# debug only
@TTTPOB
TTTPOB / bedcolumnname.r
Created October 15, 2021 13:50
bed file column name
bedcolname<- c(
"seqnames",
"start",
"end",
"name",
"score",
"strand"
)
@TTTPOB
TTTPOB / getsrr.py
Last active October 15, 2021 12:49
simple script to get srr from gsm or srx accesion, useful when you need to download many srr data
#!/usr/bin/env python3
import httpx
from bs4 import BeautifulSoup as bs
from xml.etree import ElementTree as ET
import click
import re
# see https://blog.tpob.xyz/2021/10/14/%E6%9B%B4%E5%BF%AB%E8%8E%B7%E5%BE%97srr-accession/
# for more information
@TTTPOB
TTTPOB / read_compute_matrix_result.r
Created September 24, 2021 07:15
read matrix file generated by deeptools computeMatrix into R
readComputeMatrixResult<-function(dfPath,offset=6){
library(rjson)
library(tidyverse)
df<-read_tsv(file=dfPath,col_names=F,col_types=cols(),skip=1)
metadata<-readLines(gzfile(dfPath),1)%>%str_remove("^@")%>%fromJSON(json_str=.)
dfSplited<-list()
for(i in 1:length(metadata$sample_labels)){
dfSplited<-c(
dfSplited,
@TTTPOB
TTTPOB / send.py
Created May 13, 2021 11:04
send message to wecom (企业微信) by phone number
#!/bin/env python3
## the reason why i use urllib is to minimize dependency requiremnts
## the reason i dont user serverchan (https://sc.ftqq.com/) is that i want a multiuser support
from urllib import request
import sys
import json
## Please Change xxxxxx to the value you have
CORPID="xxxxxx"
MSGSECRET="xxxxxx"
@TTTPOB
TTTPOB / 全局字体替换.css
Created April 28, 2021 04:25
全局字体替换
@namespace url(http://www.w3.org/1999/xhtml);
/*!
* custom-yahei-family.css
* https://n2o.io/go?page=custom.css
*
* Copyright 2018 Francis Zhao <francis@n2o.io>
* https://n2o.io/license
*
* Date: 2018-03-11T15:00+06:00