Update multi_omics_transcript_expression.py

#5
Files changed (1) hide show
  1. multi_omics_transcript_expression.py +52 -40
multi_omics_transcript_expression.py CHANGED
@@ -125,6 +125,17 @@ LABELS_V2 = [
125
  "Whole Blood",
126
  ]
127
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  class GenomicLRATaskHandler(ABC):
130
  """
@@ -226,37 +237,41 @@ class TranscriptExpressionHandler(GenomicLRATaskHandler):
226
 
227
  DEFAULT_LENGTH = 200_000
228
  DEFAULT_FILTER_OUT_LENGTH = 196_608
 
 
229
 
230
  def __init__(
231
  self,
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 +301,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 +334,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 +369,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 +515,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
  """
 
237
 
238
  DEFAULT_LENGTH = 200_000
239
  DEFAULT_FILTER_OUT_LENGTH = 196_608
240
+ LIGHT_LENGTH = 50_000
241
+ LIGHT_FILTER_OUT_LENGTH = 49_152
242
 
243
  def __init__(
244
  self,
245
  sequence_length: int = DEFAULT_LENGTH,
246
  filter_out_sequence_length: int = DEFAULT_FILTER_OUT_LENGTH,
247
  expression_method: str = "read_counts_old",
248
+ light_version: bool = False,
249
  **kwargs,
250
  ):
251
  """
252
+ Creates a new handler for the Transcript Expression Prediction Task.
253
  Args:
254
  sequence_length: Length of the sequence around the TSS_CAGE start site
255
+ light_version: If True, uses a smaller subset of tissues and shorter sequences
 
 
 
 
 
256
  """
257
  self.reference_genome = None
258
  self.coordinate_csv_file = None
259
  self.labels_csv_file = None
260
+ self.light_version = light_version
261
+
262
+ if light_version:
263
+ self.sequence_length = self.LIGHT_LENGTH
264
+ self.filter_out_sequence_length = self.LIGHT_FILTER_OUT_LENGTH
265
+ else:
266
+ self.sequence_length = sequence_length
267
+ self.filter_out_sequence_length = filter_out_sequence_length
268
+
269
+ if self.filter_out_sequence_length is not None:
270
+ assert isinstance(self.filter_out_sequence_length, int)
271
  assert (
272
+ self.sequence_length <= self.filter_out_sequence_length
273
+ ), f"{self.sequence_length=} > {self.filter_out_sequence_length=}"
274
+ assert isinstance(self.sequence_length, int)
275
 
276
  def get_info(self, description: str) -> DatasetInfo:
277
  """
 
301
  }
302
  )
303
  return datasets.DatasetInfo(
 
304
  description=description,
 
305
  features=features,
306
  )
307
 
 
334
  """
335
  df = pd.read_csv(self.df_csv_file)
336
  df = df.loc[df["chr"] != "chrMT"]
337
+
338
+ # Use light version labels if specified
339
+ labels_name = LABELS_LIGHT if self.light_version else LABELS_V1
340
 
341
  split_df = df.loc[df["split"] == split]
342
+
343
+ # For light version, take only a subset of the data
344
+ if self.light_version:
345
+ split_df = split_df.sample(n=min(1000, len(split_df)), random_state=42)
346
 
347
  norm_values_df = pd.read_csv(self.normalization_values_csv_file)
348
+
349
+ # Select appropriate columns based on version
350
+ label_columns = [f"m_t_{tissue}" for tissue in labels_name]
351
+ m_t = norm_values_df[label_columns].to_numpy().reshape(-1)
352
+
353
+ label_columns = [f"sigma_t_{tissue}" for tissue in labels_name]
354
+ sigma_t = norm_values_df[label_columns].to_numpy().reshape(-1)
355
+
356
+ label_columns = [f"m_g_{tissue}" for tissue in labels_name]
357
+ m_g = norm_values_df[label_columns].to_numpy().reshape(-1)
358
+
359
+ label_columns = [f"sigma_g_{tissue}" for tissue in labels_name]
360
+ sigma_g = norm_values_df[label_columns].to_numpy().reshape(-1)
 
 
 
 
 
 
 
361
 
362
  key = 0
363
  for idx, coordinates_row in split_df.iterrows():
 
369
  start = coordinates_row["start"] - 1 # -1 since vcf coords are 1-based
370
 
371
  chromosome = coordinates_row["chr"]
372
+ labels_row = coordinates_row[labels_name]
373
  padded_sequence = pad_sequence(
374
  chromosome=self.reference_genome[chromosome],
375
  start=start,
 
515
 
516
  if negative_strand:
517
  return chromosome[start:end].reverse.complement.seq
518
+ return chromosome[start:end].seq