cmatkhan commited on
Commit
4d3ffee
·
verified ·
1 Parent(s): 23e3fd4

Delete scripts

Browse files
Files changed (1) hide show
  1. scripts +0 -157
scripts DELETED
@@ -1,157 +0,0 @@
1
- ## NOTE: The data is currently on /lts/mblab/downloaded_data/barkai_checseq
2
- ## and the parquet dataset is on the brentlab-strides aws at s3://yeast-binding-perturbation-data/barkai_checkseq
3
-
4
- library(tidyverse)
5
- library(here)
6
- library(arrow)
7
-
8
- sacCer3_genome = rtracklayer::import("~/ref/sacCer3/ucsc/sacCer3.fa.gz", format="fasta")
9
-
10
- sacCer3_seqnames = unlist(map(str_split(names(sacCer3_genome), " "), ~.[[1]]))
11
-
12
- sacCer3_genome_df = tibble(
13
- seqnames = rep(sacCer3_seqnames, Biostrings::width(sacCer3_genome))
14
- ) %>%
15
- group_by(seqnames) %>%
16
- mutate(start = row_number()-1,
17
- end = row_number()) %>%
18
- ungroup()
19
-
20
- retrieve_series_paths = function(series_id){
21
- sra_meta_path = file.path("data/barkai_checseq", series_id, "SraRunTable.csv")
22
- stopifnot(file.exists(sra_meta_path))
23
- df = read_csv(sra_meta_path)
24
-
25
- data_files = list.files(here("data/barkai_checseq", series_id), "*.txt.gz", full.names = TRUE)
26
-
27
- stopifnot(nrow(df) == length(data_files))
28
-
29
- names(data_files) = str_extract(basename(data_files), "GSM\\d+")
30
-
31
- list(
32
- meta = sra_meta_path,
33
- files = data_files
34
- )
35
- }
36
-
37
-
38
- add_genomic_coordinate = function(checseqpath){
39
-
40
- bind_cols(sacCer3_genome_df,
41
- data.table::fread(checseqpath, sep = "\t", col.names='pileup'))
42
-
43
- }
44
-
45
- process_checseq_files = function(file){
46
-
47
- add_genomic_coordinate(file) %>%
48
- filter(pileup != 0)
49
- }
50
-
51
- series_list = map(set_names(c("GSE179430", "GSE209631", "GSE222268")), retrieve_series_paths)
52
-
53
- dataset_basepath = here("data/barkai_checseq/hf/genome_map")
54
-
55
- # Create output directory
56
- dir.create(dataset_basepath, recursive = TRUE, showWarnings = FALSE)
57
-
58
- for (series_id in names(series_list)) {
59
-
60
- message(glue::glue("Processing series {series_id}"))
61
-
62
- for (accession_id in names(series_list[[series_id]]$files)) {
63
-
64
- message(glue::glue(" Processing {accession_id}"))
65
-
66
- df <- process_checseq_files(
67
- series_list[[series_id]]$files[[accession_id]]
68
- ) %>%
69
- mutate(accession = accession_id, series = series_id)
70
-
71
- df %>%
72
- group_by(seqnames) %>%
73
- write_dataset(
74
- path = dataset_basepath,
75
- format = "parquet",
76
- partitioning = c("series", "accession"),
77
- existing_data_behavior = "overwrite",
78
- compression = "zstd",
79
- write_statistics = TRUE,
80
- use_dictionary = c(
81
- seqnames = TRUE
82
- )
83
- )
84
-
85
- gc()
86
- }
87
- }
88
-
89
- # the following code was used to parse an entire series to DF and then save
90
- # to a parquet dataset. that was too large and I chose the dataset partitioning
91
- # instead.
92
-
93
- # split_manipulation <- function(manipulation_str) {
94
- # parts <- str_split(manipulation_str, "::")[[1]]
95
- #
96
- # if (length(parts) != 2) {
97
- # stop("Unexpected format. Expected 'LOCUS::TAGGED_CONSTRUCT'")
98
- # }
99
- #
100
- # tagged_locus <- parts[1]
101
- # rhs <- parts[2]
102
- #
103
- # # default
104
- # dbd_donor_symbol_str <- "none"
105
- # ortholog <- "none"
106
- #
107
- # # Check for paralog DBD
108
- # if (str_detect(rhs, "-[A-Za-z0-9]+DBD-Mnase$")) {
109
- # dbd_donor_symbol_str <- toupper(str_remove(str_split(rhs, "-", simplify = TRUE)[[2]], "DBD"))
110
- # } else if (str_detect(rhs, "^K\\.lactis .*?-Mnase$")) {
111
- # ortholog <- rhs
112
- # }
113
- #
114
- # list(
115
- # mnase_tagged_symbol = tagged_locus,
116
- # dbd_donor_symbol = dbd_donor_symbol_str,
117
- # ortholog_donor = ortholog
118
- # )
119
- # }
120
- #
121
- #
122
- # split_deletion <- function(deletion_str) {
123
- # parts <- str_split(deletion_str, "::", simplify = TRUE)
124
- #
125
- # list(
126
- # paralog_deletion_symbol = parts[1],
127
- # paralog_resistance_cassette = if (ncol(parts) >= 2) parts[2] else "none"
128
- # )
129
- # }
130
- #
131
- # split_construct_to_tibble = function(split_list){
132
- # background = list(background=split_list[[1]])
133
- # manipulation_list = split_manipulation(split_list[[2]])
134
- # deletion_list = split_deletion(tryCatch(split_list[[3]], error = function(e) "none"))
135
- #
136
- # bind_cols(map(list(background, manipulation_list, deletion_list), as_tibble))
137
- #
138
- # }
139
- #
140
- #
141
- # split_constructs <- function(s) {
142
- # s <- str_trim(s)
143
- # if (s == "" || is.na(s)) return(character(0))
144
- # # split on spaces ONLY when the next token starts a new locus "XYZ::"
145
- # split_geno = str_split(s, "\\s+(?=[A-Za-z0-9_.()\\-]+::)")[[1]]
146
- #
147
- # bind_cols(tibble(genotype = s), split_construct_to_tibble(split_geno))
148
- #
149
- #
150
- # }
151
- #
152
- # gse178430_parsed_meta = bind_cols(
153
- # select(gse178430_meta, `GEO_Accession (exp)`, strainid, Instrument) %>%
154
- # dplyr::rename(accession = `GEO_Accession (exp)`,
155
- # instrument = Instrument),
156
- # bind_rows(map(gse178430_meta$genotype, split_constructs))
157
- # )