Update multi_omics_transcript_expression.py
Browse files124 unmodified lines125126127128129130101 unmodified lines23223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126223 unmodified lines28628728828929029129229329426 unmodified lines3213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503515 unmodified lines357358359360361362363139 unmodified lines503504505506124 unmodified lines"Whole Blood",]class GenomicLRATaskHandler(ABC):"""101 unmodified linessequence_length: int = DEFAULT_LENGTH,filter_out_sequence_length: int = DEFAULT_FILTER_OUT_LENGTH,expression_method: str = "read_counts_old",**kwargs,):"""Creates a new handler for the Transcrpt Expression Prediction Task.Args:sequence_length: Length of the sequence around the TSS_CAGE start siteInstance Vars:reference_genome: The Fasta extracted reference genome.coordinate_csv_file: The csv file that stores the coordinates and filename of the targetlabels_csv_file: The csv file that stores the labels with one sample per row.sequence_length: Sequence length for this handler.counts."""self.reference_genome = Noneself.coordinate_csv_file = Noneself.labels_csv_file = Noneself.sequence_length = sequence_lengthself.filter_out_sequence_length = filter_out_sequence_lengthif filter_out_sequence_length is not None:assert isinstance(filter_out_sequence_length, int)assert (sequence_length <= filter_out_sequence_length), f"{sequence_length=} > {filter_out_sequence_length=}"assert isinstance(sequence_length, int)def get_info(self, description: str) -> DatasetInfo:"""23 unmodified lines})return datasets.DatasetInfo(# This is the description that will appear on the datasets page.description=description,# This defines the different columns of the dataset and their typesfeatures=features,)26 unmodified lines"""df = pd.read_csv(self.df_csv_file)df = df.loc[df["chr"] != "chrMT"]labels_name = LABELS_V1split_df = df.loc[df["split"] == split]norm_values_df = pd.read_csv(self.normalization_values_csv_file)m_t = (norm_values_df[[f"m_t_{tissue}" for tissue in LABELS_V1]].to_numpy().reshape(-1))sigma_t = (norm_values_df[[f"sigma_t_{tissue}" for tissue in LABELS_V1]].to_numpy().reshape(-1))m_g = (norm_values_df[[f"m_g_{tissue}" for tissue in LABELS_V1]].to_numpy().reshape(-1))sigma_g = (norm_values_df[[f"sigma_g_{tissue}" for tissue in LABELS_V1]].to_numpy().reshape(-1))key = 0for idx, coordinates_row in split_df.iterrows():5 unmodified linesstart = coordinates_row["start"] - 1 # -1 since vcf coords are 1-basedchromosome = coordinates_row["chr"]labels_row = coordinates_row[LABELS_V1]padded_sequence = pad_sequence(chromosome=self.reference_genome[chromosome],start=start,139 unmodified linesif negative_strand:return chromosome[start:end].reverse.complement.seqreturn chromosome[start:end].seq124 unmodified lines125126127128129130131132133134135136137138139140141101 unmodified lines24324424524624724824925025125225325425525625725825926026126226326426526626726826927023 unmodified lines29429529629729829930026 unmodified lines3273283293303313323333343353363373383393403413423433443453463473483493503513523533543553565 unmodified lines362363364365366367368139 unmodified lines508509510511124 unmodified lines"Whole Blood",]# Add after LABELS_V2 definitionLABELS_LIGHT = ["Adipose Tissue","Brain","Heart","Liver","Lung","Muscle","Pancreas","Skin",]class GenomicLRATaskHandler(ABC):"""101 unmodified linessequence_length: int = DEFAULT_LENGTH,filter_out_sequence_length: int = DEFAULT_FILTER_OUT_LENGTH,expression_method: str = "read_counts_old",light_version: bool = False,**kwargs,):"""Creates a new handler for the Transcript Expression Prediction Task.Args:sequence_length: Length of the sequence around the TSS_CAGE start sitelight_version: If True, uses a smaller subset of tissues and fewer samples"""self.reference_genome = Noneself.coordinate_csv_file = Noneself.labels_csv_file = Noneself.light_version = light_versionself.sequence_length = sequence_lengthself.filter_out_sequence_length = filter_out_sequence_lengthif self.filter_out_sequence_length is not None:assert isinstance(self.filter_out_sequence_length, int)assert (self.sequence_length <= self.filter_out_sequence_length), f"{self.sequence_length=} > {self.filter_out_sequence_length=}"assert isinstance(self.sequence_length, int)def get_info(self, description: str) -> DatasetInfo:"""23 unmodified lines})return datasets.DatasetInfo(description=description,features=features,)26 unmodified lines"""df = pd.read_csv(self.df_csv_file)df = df.loc[df["chr"] != "chrMT"]# Use light version labels if specifiedlabels_name = LABELS_LIGHT if self.light_version else LABELS_V1split_df = df.loc[df["split"] == split]# For light version, take only a subset of the dataif self.light_version:split_df = split_df.sample(n=min(1000, len(split_df)), random_state=42)norm_values_df = pd.read_csv(self.normalization_values_csv_file)# Select appropriate columns based on versionlabel_columns = [f"m_t_{tissue}" for tissue in labels_name]m_t = norm_values_df[label_columns].to_numpy().reshape(-1)label_columns = [f"sigma_t_{tissue}" for tissue in labels_name]sigma_t = norm_values_df[label_columns].to_numpy().reshape(-1)label_columns = [f"m_g_{tissue}" for tissue in labels_name]m_g = norm_values_df[label_columns].to_numpy().reshape(-1)label_columns = [f"sigma_g_{tissue}" for tissue in labels_name]sigma_g = norm_values_df[label_columns].to_numpy().reshape(-1)key = 0for idx, coordinates_row in split_df.iterrows():5 unmodified linesstart = coordinates_row["start"] - 1 # -1 since vcf coords are 1-basedchromosome = coordinates_row["chr"]labels_row = coordinates_row[labels_name]padded_sequence = pad_sequence(chromosome=self.reference_genome[chromosome],start=start,139 unmodified linesif negative_strand:return chromosome[start:end].reverse.complement.seqreturn chromosome[start:end].seq
multi_omics_transcript_expression.py+42-37