Create cache folder

#3
Files changed (1) hide show
  1. multi_omics_transcript_expression.py +37 -43
multi_omics_transcript_expression.py CHANGED
@@ -125,17 +125,6 @@ LABELS_V2 = [
125
  "Whole Blood",
126
  ]
127
 
128
- # Add after LABELS_V2 definition
129
- LABELS_LIGHT = [
130
- "Adipose Tissue",
131
- "Brain",
132
- "Heart",
133
- "Liver",
134
- "Lung",
135
- "Muscle",
136
- "Pancreas",
137
- "Skin",
138
- ]
139
 
140
  class GenomicLRATaskHandler(ABC):
141
  """
@@ -213,7 +202,6 @@ class GenomicLRATaskHandler(ABC):
213
 
214
  if not os.path.exists(file_complete_path):
215
  if not os.path.exists(file_complete_path + ".gz"):
216
- os.makedirs(os.path.dirname(file_complete_path), exist_ok=True)
217
  with tqdm(
218
  unit="B",
219
  unit_scale=True,
@@ -243,28 +231,31 @@ class TranscriptExpressionHandler(GenomicLRATaskHandler):
243
  sequence_length: int = DEFAULT_LENGTH,
244
  filter_out_sequence_length: int = DEFAULT_FILTER_OUT_LENGTH,
245
  expression_method: str = "read_counts_old",
246
- light_version: bool = False,
247
  **kwargs,
248
  ):
249
  """
250
- Creates a new handler for the Transcript Expression Prediction Task.
251
  Args:
252
  sequence_length: Length of the sequence around the TSS_CAGE start site
253
- light_version: If True, uses a smaller subset of tissues and fewer samples
 
 
 
 
 
254
  """
255
  self.reference_genome = None
256
  self.coordinate_csv_file = None
257
  self.labels_csv_file = None
258
- self.light_version = light_version
259
  self.sequence_length = sequence_length
260
  self.filter_out_sequence_length = filter_out_sequence_length
261
 
262
- if self.filter_out_sequence_length is not None:
263
- assert isinstance(self.filter_out_sequence_length, int)
264
  assert (
265
- self.sequence_length <= self.filter_out_sequence_length
266
- ), f"{self.sequence_length=} > {self.filter_out_sequence_length=}"
267
- assert isinstance(self.sequence_length, int)
268
 
269
  def get_info(self, description: str) -> DatasetInfo:
270
  """
@@ -294,7 +285,9 @@ class TranscriptExpressionHandler(GenomicLRATaskHandler):
294
  }
295
  )
296
  return datasets.DatasetInfo(
 
297
  description=description,
 
298
  features=features,
299
  )
300
 
@@ -327,30 +320,31 @@ class TranscriptExpressionHandler(GenomicLRATaskHandler):
327
  """
328
  df = pd.read_csv(self.df_csv_file)
329
  df = df.loc[df["chr"] != "chrMT"]
330
-
331
- # Use light version labels if specified
332
- labels_name = LABELS_LIGHT if self.light_version else LABELS_V1
333
 
334
  split_df = df.loc[df["split"] == split]
335
-
336
- # For light version, take only a subset of the data
337
- if self.light_version:
338
- split_df = split_df.sample(n=min(1000, len(split_df)), random_state=42)
339
 
340
  norm_values_df = pd.read_csv(self.normalization_values_csv_file)
341
-
342
- # Select appropriate columns based on version
343
- label_columns = [f"m_t_{tissue}" for tissue in labels_name]
344
- m_t = norm_values_df[label_columns].to_numpy().reshape(-1)
345
-
346
- label_columns = [f"sigma_t_{tissue}" for tissue in labels_name]
347
- sigma_t = norm_values_df[label_columns].to_numpy().reshape(-1)
348
-
349
- label_columns = [f"m_g_{tissue}" for tissue in labels_name]
350
- m_g = norm_values_df[label_columns].to_numpy().reshape(-1)
351
-
352
- label_columns = [f"sigma_g_{tissue}" for tissue in labels_name]
353
- sigma_g = norm_values_df[label_columns].to_numpy().reshape(-1)
 
 
 
 
 
 
 
354
 
355
  key = 0
356
  for idx, coordinates_row in split_df.iterrows():
@@ -362,7 +356,7 @@ class TranscriptExpressionHandler(GenomicLRATaskHandler):
362
  start = coordinates_row["start"] - 1 # -1 since vcf coords are 1-based
363
 
364
  chromosome = coordinates_row["chr"]
365
- labels_row = coordinates_row[labels_name]
366
  padded_sequence = pad_sequence(
367
  chromosome=self.reference_genome[chromosome],
368
  start=start,
@@ -508,4 +502,4 @@ def pad_sequence(
508
 
509
  if negative_strand:
510
  return chromosome[start:end].reverse.complement.seq
511
- return chromosome[start:end].seq
 
125
  "Whole Blood",
126
  ]
127
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  class GenomicLRATaskHandler(ABC):
130
  """
 
202
 
203
  if not os.path.exists(file_complete_path):
204
  if not os.path.exists(file_complete_path + ".gz"):
 
205
  with tqdm(
206
  unit="B",
207
  unit_scale=True,
 
231
  sequence_length: int = DEFAULT_LENGTH,
232
  filter_out_sequence_length: int = DEFAULT_FILTER_OUT_LENGTH,
233
  expression_method: str = "read_counts_old",
 
234
  **kwargs,
235
  ):
236
  """
237
+ Creates a new handler for the Transcrpt Expression Prediction Task.
238
  Args:
239
  sequence_length: Length of the sequence around the TSS_CAGE start site
240
+ Instance Vars:
241
+ reference_genome: The Fasta extracted reference genome.
242
+ coordinate_csv_file: The csv file that stores the coordinates and filename of the target
243
+ labels_csv_file: The csv file that stores the labels with one sample per row.
244
+ sequence_length: Sequence length for this handler.
245
+ counts.
246
  """
247
  self.reference_genome = None
248
  self.coordinate_csv_file = None
249
  self.labels_csv_file = None
 
250
  self.sequence_length = sequence_length
251
  self.filter_out_sequence_length = filter_out_sequence_length
252
 
253
+ if filter_out_sequence_length is not None:
254
+ assert isinstance(filter_out_sequence_length, int)
255
  assert (
256
+ sequence_length <= filter_out_sequence_length
257
+ ), f"{sequence_length=} > {filter_out_sequence_length=}"
258
+ assert isinstance(sequence_length, int)
259
 
260
  def get_info(self, description: str) -> DatasetInfo:
261
  """
 
285
  }
286
  )
287
  return datasets.DatasetInfo(
288
+ # This is the description that will appear on the datasets page.
289
  description=description,
290
+ # This defines the different columns of the dataset and their types
291
  features=features,
292
  )
293
 
 
320
  """
321
  df = pd.read_csv(self.df_csv_file)
322
  df = df.loc[df["chr"] != "chrMT"]
323
+ labels_name = LABELS_V1
 
 
324
 
325
  split_df = df.loc[df["split"] == split]
 
 
 
 
326
 
327
  norm_values_df = pd.read_csv(self.normalization_values_csv_file)
328
+ m_t = (
329
+ norm_values_df[[f"m_t_{tissue}" for tissue in LABELS_V1]]
330
+ .to_numpy()
331
+ .reshape(-1)
332
+ )
333
+ sigma_t = (
334
+ norm_values_df[[f"sigma_t_{tissue}" for tissue in LABELS_V1]]
335
+ .to_numpy()
336
+ .reshape(-1)
337
+ )
338
+ m_g = (
339
+ norm_values_df[[f"m_g_{tissue}" for tissue in LABELS_V1]]
340
+ .to_numpy()
341
+ .reshape(-1)
342
+ )
343
+ sigma_g = (
344
+ norm_values_df[[f"sigma_g_{tissue}" for tissue in LABELS_V1]]
345
+ .to_numpy()
346
+ .reshape(-1)
347
+ )
348
 
349
  key = 0
350
  for idx, coordinates_row in split_df.iterrows():
 
356
  start = coordinates_row["start"] - 1 # -1 since vcf coords are 1-based
357
 
358
  chromosome = coordinates_row["chr"]
359
+ labels_row = coordinates_row[LABELS_V1]
360
  padded_sequence = pad_sequence(
361
  chromosome=self.reference_genome[chromosome],
362
  start=start,
 
502
 
503
  if negative_strand:
504
  return chromosome[start:end].reverse.complement.seq
505
+ return chromosome[start:end].seq