-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslice_constants.ts
232 lines (209 loc) · 7.71 KB
/
slice_constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import axios from "axios";
const config = require("config");
const _ = require('underscore');
import {Configs, ProjectConfigs} from "./types";
import path from "path";
export class SliceConstants {
/**
*
* @private
*/
public static REPLACE_PROJECT_NAMES = [
'LEVEL4_LFC_COMBAT_*.csv',
'LEVEL5_LFC_COMBAT_*.csv'
];
/**
* Rows with pert_ids in this project are retained
* @type {string[]}
*/
private static ROW_FILES_POST_FIX = [
'_continuous_associations.csv',
'_discrete_associations.csv',
'_DRC_TABLE.csv',
'_LEVEL3_LMFI_*.csv',
'_LEVEL4_LFC_COMBAT_*.csv',
'_LEVEL4_LFC_n*.csv',
'_LEVEL5_LFC_COMBAT_*.csv',
'_LEVEL5_LFC_n*.csv',
'_model_table.csv'
// '_RF_table.csv',
];
/**
* Files available from compound directories to be put into
* the project data directory
* @private
*/
public static PROJECT_DATA_FILES = [
'continuous_associations.csv',
'discrete_associations.csv',
'DRC_TABLE.csv',
'LEVEL3_LMFI_*.csv',
'LEVEL4_LFC_COMBAT_*.csv',
'LEVEL5_LFC_COMBAT_*.csv',
'model_table.csv',
'RF_table.csv',
];
/**
* Rows with pert plates in this project are retained
* @type {string[]}
*/
private static QC_PLATE_FILES_POST_FIX = [
'_QC_TABLE.csv'
];
private static INST_INFO_FILES_POST_FIX: string[] = [
'_inst_info.txt'
];
/**
* Rows with pert plates in this project are retained
* @type {string[]}
*/
private static PLATE_FILES_POST_FIX = [
'_LEVEL2*.csv'
];
/**
* Files to copy from source to destination
* @type {string[]}
*/
private static COPY_FILES_POST_FIX = [
'_cell_info.txt'
];
/**
* Columns with pert-ids not part of this project are removed from these files
* @type {string[]}
*/
private static COLUMN_FILES_POST_FIX = [
'_IC50_MATRIX.csv',
'_LFC_MATRIX.csv',
'_AUC_MATRIX.csv'
];
/**
* Destination files to zip
* @type {string[]}
*/
private static FILES_TO_ZIP = [
'_AUC_MATRIX.csv',
'_continuous_associations.csv',
'_discrete_associations.csv',
'_DRC_TABLE.csv',
'_IC50_MATRIX.csv',
'_LEVEL3_LMFI_*.csv',
'_LEVEL4_LFC_COMBAT_*.csv',
'_LEVEL5_LFC_COMBAT_*.csv',
'_LFC_MATRIX.csv',
'_model_table.csv',
'_RF_table.csv',
'_QC_TABLE.csv'
];
public constructor() {
}
/**
* Executes a shell command and return it as a Promise.
* @param cmd {string}
* @return {Promise<string>}
*/
public static execShellCommand(cmd:string) {
const exec = require('child_process').exec;
return new Promise((resolve, reject) => {
exec(cmd, (error:any, stdout:any, stderr:any) => {
if (error) {
console.log(error);
}
resolve(stdout? stdout : stderr);
});
});
}
public static matcher(pert_inames: string[],input: string) {
const g = pert_inames.join("|");
const PERT_INAMES_REG_EXP = new RegExp(g);
return PERT_INAMES_REG_EXP.test(input);
}
private static async fetchData (screen:string) {
const BASE_API_URL = config.get("base_url");
const API_KEY = config.get("api_key");
const filter = {where: {screen: screen}, order: "project_id ASC"};
const url = BASE_API_URL + "/v_mts_projects_per_plates?filter=" + JSON.stringify(filter);
const response = await axios.get(url, {
headers: {
'user_key': API_KEY,
'Content-Type': 'application/json'
}
});
return response.data;
}
public static async fetchDataByScreen(screen:string){
const projectData = await SliceConstants.fetchData(screen);
const projects = _.uniq(_.pluck(projectData, "project_id"));
let fileInfos: Configs[] = [];
for (let project of projects) {
const currentProjects = _.where(projectData, {project_id: project}) as string[]
const pert_plates = _.uniq(_.pluck(currentProjects, "pert_plate")) as string[]
const pert_ids = _.uniq(_.pluck(currentProjects, "pert_id")) as string[]
const pert_inames = _.uniq(_.pluck(currentProjects, "pert_iname")) as string[]
//TODO type this
fileInfos.push({
SCREEN: screen,
DATA_SRC_DIR : "data-to-extract",
PARENT_SRC_PROJECT_DIR: "data-to-extract/build",
PARENT_DEST_PROJECT_DIR: project.toLowerCase(),
PERT_INAMES: pert_inames,
PERT_IDS: pert_ids,
PERT_PLATES: pert_plates,
PROJECT: project
});
}
return fileInfos;
}
public static getOutputFileName(file:string,projectConfigs: ProjectConfigs){
let outputFileName = file.replace(projectConfigs.SOURCE_DATA_DIR, projectConfigs.DESTINATION_DATA_DIR);
outputFileName = outputFileName.replace(projectConfigs.OLD_PROJECT_PREFIX, projectConfigs.NEW_PROJECT_PREFIX);
const fileName = path.basename(outputFileName);
const nFileName = fileName.replace(projectConfigs.SCREEN,projectConfigs.PROJECT)
return outputFileName.replace(fileName,nFileName);
}
public static prepareConstants(configs: Configs): ProjectConfigs {
const OLD_PROJECT_DIR = configs.PARENT_SRC_PROJECT_DIR.toUpperCase();
//The directory to host the source files
const SOURCE_DIR = configs.PARENT_SRC_PROJECT_DIR;
//The new project prefix
const NEW_PROJECT_DIR = configs.PARENT_DEST_PROJECT_DIR.toUpperCase();
//The directory that would host the processed files
const DESTINATION_DIR = configs.PARENT_DEST_PROJECT_DIR + '/' + NEW_PROJECT_DIR;
//pert-inames that should be retained
const PERT_INAMES = configs.PERT_INAMES;
//The pert ids that should be retained
const PERT_IDS = configs.PERT_IDS;
//The pert plates that should be retained
const PERT_PLATES = configs.PERT_PLATES;
//The directory to host the source files
const SOURCE_DATA_DIR = SOURCE_DIR;
//The directory that would host the processed files
const DESTINATION_DATA_DIR = DESTINATION_DIR + "/data";
//The old project prefix
const OLD_PROJECT_PREFIX = OLD_PROJECT_DIR + "_";
//The new project prefix
const NEW_PROJECT_PREFIX = NEW_PROJECT_DIR + "_";
//TODO. add downloads file
return {
SCREEN: configs.SCREEN,
INST_INFO_FILES_POST_FIX: SliceConstants.INST_INFO_FILES_POST_FIX,
QC_PLATE_FILES_POST_FIX: SliceConstants.QC_PLATE_FILES_POST_FIX,
COLUMN_FILES_POST_FIX: SliceConstants.COLUMN_FILES_POST_FIX,
ROW_FILES_POST_FIX: SliceConstants.ROW_FILES_POST_FIX,
NEW_PROJECT_PREFIX: NEW_PROJECT_PREFIX,
OLD_PROJECT_PREFIX: OLD_PROJECT_PREFIX,
SOURCE_DATA_DIR: SOURCE_DATA_DIR,
DESTINATION_DATA_DIR: DESTINATION_DATA_DIR,
PERT_INAMES: PERT_INAMES,
PERT_IDS: PERT_IDS,
PERT_PLATES: PERT_PLATES,
PLATE_FILES_POST_FIX: SliceConstants.PLATE_FILES_POST_FIX,
COPY_FILES_POST_FIX: SliceConstants.COPY_FILES_POST_FIX,
FILES_TO_ZIP: SliceConstants.FILES_TO_ZIP,
DESTINATION_DIR: DESTINATION_DIR,
SOURCE_DIR: SOURCE_DIR,
OLD_PROJECT_DIR: OLD_PROJECT_DIR,
NEW_PROJECT_DIR: NEW_PROJECT_DIR,
PROJECT: configs.PROJECT
}
}
}