Skip to content

Instantly share code, notes, and snippets.

@allenday
allenday / rice3k-hw-equilibrium-qplot.R
Created March 6, 2019 10:51
Rice3K analysis 2: dataviz some specific regions are under selective pressure
data = read.csv("~/data.csv")
colnames(data) <- c("contig", "pos", "t", "f", "value", "value2")
qplot(data=data, x=pos,y=1,color=value, alpha=I(1),geom="jitter",facets=contig ~ ., main="Position vs. % of Alleles out of Hardy-Weinberg Equilibrium (p<=0.05)", xlab="Chromosome Position (Bin Size=10Kb)",ylab="") + theme_bw() + theme(axis.title = element_text(size = 15), axis.ticks.y=element_blank(),axis.text.y=element_blank()) + scale_x_continuous() + guides(colour = guide_legend(override.aes = list(alpha = 1))) + scale_colour_gradient(low="white",high="red")
@allenday
allenday / rice3k-selective-pressure-heatmap.R
Created March 6, 2019 08:42
Rice 3K analysis 1: dataviz of genetic variant distribution
rice3k = read.csv("~/Downloads/rice3k_z.csv",header=F)
#chromosomes 1-12, excludes Sy and Un
rice3k.z = as.matrix(rice3k[,c(2:45,129:165,166:202,203:239,240:270,271:302,303:333,334:362,363:386,46:69,70:99,100:128)])
rownames(rice3k.z) = rice3k[,1]
colnames(rice3k.z) = c(rep(1,44),rep(2,37),rep(3,37),rep(4,37),rep(5,31),rep(6,32),rep(7,31),rep(8,29),rep(9,24),rep(10,24),rep(11,30),rep(12,29))
heatmap(rice3k.z,Colv=NA,ColSideColors=colnames(rice3k.z),labCol=F,scale="none",cexRow=0.1)
#2:45 #1
#46:69 #10
#70:99 #11
#100:128 #12
@allenday
allenday / rice3k-selective-pressure-anomalies.sql
Created March 6, 2019 08:39
Rice 3K analysis 1: genetic variants are not uniformly distributed
WITH
ind AS (
-- count variants for each sample/ref/bin
SELECT
call.name AS sample, reference_name AS ref, CAST(start_position/1000000 AS INT64) AS bin, COUNT(call.name) AS n
FROM `bigquery-public-data.genomics_rice.Rice3K_DeepVariant_Os_Nipponbare_Reference_IRGSP_1_0`
JOIN UNNEST(call) AS call
JOIN UNNEST(alternate_bases) AS alt
WHERE alt.alt != '<*>'
GROUP BY sample, ref, bin
@allenday
allenday / example-rice-fastq.fq
Created February 13, 2019 10:06
small snippet of rice chr1
@example-rice-fastq
CTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAACCCTAAACCCTAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACCCTAAACAGCTGACAGTACGATAGATCCACGCGAGAGGAAC
+
"##"""""#1'##.&&'#&(&'($&'+)""#"##"""$#&*&+),&$##$*-(,-1850*(&###&(*'&&),//($'*(%'#%##(('"$"&#"$')&$"$&+($#"$(%%"""""#$$"%##"%#%""'$#+*,$,*%%$%"&$++$"
@allenday
allenday / bitcoin-cash.sql
Last active June 16, 2022 21:32
What are the current balances of a random set of 1000 addresses on blockchain X?
WITH double_entry_book AS (
-- debits
SELECT
ARRAY_TO_STRING(inputs.addresses, ",") AS address
, inputs.type
, -inputs.value AS value
FROM `bigquery-public-data.crypto_bitcoin_cash.transactions` JOIN UNNEST(inputs) AS inputs
WHERE block_timestamp_month = '2019-01-01'
UNION ALL
@allenday
allenday / gini-balance-bitcoin.sql
Created January 31, 2019 10:31
Calculate Gini coefficient for Bitcoin balances.
WITH double_entry_book AS (
-- debits
SELECT
array_to_string(inputs.addresses, ",") as address
, inputs.type
, -inputs.value as value
, block_timestamp
FROM `bigquery-public-data.crypto_bitcoin.inputs` as inputs
UNION ALL
@allenday
allenday / gini-balance-ethereum.sql
Created January 31, 2019 10:27
Calculate Gini coefficient for Ethereum balances.
with
double_entry_book as (
-- debits
select to_address as address, value as value, block_timestamp
from `bigquery-public-data.crypto_ethereum.traces`
where to_address is not null
and status = 1
and (call_type not in ('delegatecall', 'callcode', 'staticcall') or call_type is null)
union all
-- credits
@allenday
allenday / gini-balance-erc20.sql
Created January 31, 2019 10:14
Calculate Gini coefficient for ERC-20 balances.
with
double_entry_book as (
-- debits
select to_address as address, CAST(value AS NUMERIC) as value, block_timestamp
from `bigquery-public-data.crypto_ethereum.token_transfers`
where from_address is not null and to_address is not null
and token_address = LOWER('0x408e41876cccdc0f92210600ef50372656052a38') --OMG
union all
-- credits
select from_address as address, -CAST(value AS NUMERIC) as value, block_timestamp
@allenday
allenday / .block
Last active January 25, 2019 09:10 — forked from mbostock/.block
Force Layout from CSV
license: gpl-3.0
@allenday
allenday / transacting-partner-count.sql
Created January 25, 2019 08:27
Number of transacting partners per Bitcoin address
SELECT
txn_count,
COUNT(txn_count) AS num_addresses
FROM
(
SELECT
ARRAY_TO_STRING(inputs.addresses, '') AS addresses,
COUNT(DISTINCT `hash`) AS txn_count
FROM `crypto-etl-ethereum-dev.bitcoin_blockchain.transactions` AS txns
CROSS JOIN UNNEST(txns.inputs) AS inputs