Update multi_omics_transcript_expression.py

#6
Files changed (1) hide show
  1. multi_omics_transcript_expression.py +42 -37
multi_omics_transcript_expression.py CHANGED
@@ -125,6 +125,17 @@ LABELS_V2 = [
125
  "Whole Blood",
126
  ]
127
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  class GenomicLRATaskHandler(ABC):
130
  """
@@ -232,31 +243,28 @@ class TranscriptExpressionHandler(GenomicLRATaskHandler):
232
  sequence_length: int = DEFAULT_LENGTH,
233
  filter_out_sequence_length: int = DEFAULT_FILTER_OUT_LENGTH,
234
  expression_method: str = "read_counts_old",
 
235
  **kwargs,
236
  ):
237
  """
238
- Creates a new handler for the Transcrpt Expression Prediction Task.
239
  Args:
240
  sequence_length: Length of the sequence around the TSS_CAGE start site
241
- Instance Vars:
242
- reference_genome: The Fasta extracted reference genome.
243
- coordinate_csv_file: The csv file that stores the coordinates and filename of the target
244
- labels_csv_file: The csv file that stores the labels with one sample per row.
245
- sequence_length: Sequence length for this handler.
246
- counts.
247
  """
248
  self.reference_genome = None
249
  self.coordinate_csv_file = None
250
  self.labels_csv_file = None
 
251
  self.sequence_length = sequence_length
252
  self.filter_out_sequence_length = filter_out_sequence_length
253
 
254
- if filter_out_sequence_length is not None:
255
- assert isinstance(filter_out_sequence_length, int)
256
  assert (
257
- sequence_length <= filter_out_sequence_length
258
- ), f"{sequence_length=} > {filter_out_sequence_length=}"
259
- assert isinstance(sequence_length, int)
260
 
261
  def get_info(self, description: str) -> DatasetInfo:
262
  """
@@ -286,9 +294,7 @@ class TranscriptExpressionHandler(GenomicLRATaskHandler):
286
  }
287
  )
288
  return datasets.DatasetInfo(
289
- # This is the description that will appear on the datasets page.
290
  description=description,
291
- # This defines the different columns of the dataset and their types
292
  features=features,
293
  )
294
 
@@ -321,31 +327,30 @@ class TranscriptExpressionHandler(GenomicLRATaskHandler):
321
  """
322
  df = pd.read_csv(self.df_csv_file)
323
  df = df.loc[df["chr"] != "chrMT"]
324
- labels_name = LABELS_V1
 
 
325
 
326
  split_df = df.loc[df["split"] == split]
 
 
 
 
327
 
328
  norm_values_df = pd.read_csv(self.normalization_values_csv_file)
329
- m_t = (
330
- norm_values_df[[f"m_t_{tissue}" for tissue in LABELS_V1]]
331
- .to_numpy()
332
- .reshape(-1)
333
- )
334
- sigma_t = (
335
- norm_values_df[[f"sigma_t_{tissue}" for tissue in LABELS_V1]]
336
- .to_numpy()
337
- .reshape(-1)
338
- )
339
- m_g = (
340
- norm_values_df[[f"m_g_{tissue}" for tissue in LABELS_V1]]
341
- .to_numpy()
342
- .reshape(-1)
343
- )
344
- sigma_g = (
345
- norm_values_df[[f"sigma_g_{tissue}" for tissue in LABELS_V1]]
346
- .to_numpy()
347
- .reshape(-1)
348
- )
349
 
350
  key = 0
351
  for idx, coordinates_row in split_df.iterrows():
@@ -357,7 +362,7 @@ class TranscriptExpressionHandler(GenomicLRATaskHandler):
357
  start = coordinates_row["start"] - 1 # -1 since vcf coords are 1-based
358
 
359
  chromosome = coordinates_row["chr"]
360
- labels_row = coordinates_row[LABELS_V1]
361
  padded_sequence = pad_sequence(
362
  chromosome=self.reference_genome[chromosome],
363
  start=start,
@@ -503,4 +508,4 @@ def pad_sequence(
503
 
504
  if negative_strand:
505
  return chromosome[start:end].reverse.complement.seq
506
- return chromosome[start:end].seq
 
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
  """
 
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
  }
295
  )
296
  return datasets.DatasetInfo(
 
297
  description=description,
 
298
  features=features,
299
  )
300
 
 
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
  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
 
509
  if negative_strand:
510
  return chromosome[start:end].reverse.complement.seq
511
+ return chromosome[start:end].seq