Skip to content
Snippets Groups Projects
Commit 6b25546e authored by Hugo Gillet's avatar Hugo Gillet
Browse files

Update match_reprtranscript_expressionlevel.py

parent add405d4
No related branches found
No related tags found
No related merge requests found
### Made by Hugo Gillet ### ### Made by Hugo Gillet ###
import pandas as pd import pandas as pd
import json import json
import re
import representative as repr import representative as repr
import os
def dict_reprTrans_to_df(dict_reprTrans: dict[str, str]) -> pd.DataFrame: def dict_reprTrans_to_df(dict_reprTrans: dict[str, str]) -> pd.DataFrame:
...@@ -169,12 +167,14 @@ def match_byGene( ...@@ -169,12 +167,14 @@ def match_byGene(
return df_clean return df_clean
def output_tsv(dataframe: pd.DataFrame) -> pd.DataFrame: def output_tsv(dataframe: pd.DataFrame, output_path:str) -> str:
"""Convert pandas dataframe into a tsv file """Convert pandas dataframe into a tsv file
Args: Args:
dataframe (str): Pandas dataframe containing dataframe : Pandas dataframe containing
representative transcripts and their expression level representative transcripts and their expression level
output_path : path indicating were the tsv file should be written
Returns: Returns:
Tsv file containing representative transcripts Tsv file containing representative transcripts
...@@ -186,10 +186,10 @@ def output_tsv(dataframe: pd.DataFrame) -> pd.DataFrame: ...@@ -186,10 +186,10 @@ def output_tsv(dataframe: pd.DataFrame) -> pd.DataFrame:
pass pass
csv_file = dataframe.to_csv( csv_file = dataframe.to_csv(
os.getcwd() + "\ReprTrans_ExpressionLevel.tsv", output_path,
sep="\t", sep="\t",
index=False, index=False,
header=False, header=True,
) )
return csv_file return csv_file
...@@ -198,7 +198,7 @@ def output_tsv(dataframe: pd.DataFrame) -> pd.DataFrame: ...@@ -198,7 +198,7 @@ def output_tsv(dataframe: pd.DataFrame) -> pd.DataFrame:
def match_reprTranscript_expressionLevel( def match_reprTranscript_expressionLevel(
exprTrans: str, dict_reprTrans: dict, intermediate_file: str exprTrans: str, dict_reprTrans: dict, intermediate_file: str,
): ):
"""Combine functions to replace transcripts from an expression level csv/tsv file """Combine functions to replace transcripts from an expression level csv/tsv file
with representative transcripts with representative transcripts
...@@ -210,6 +210,7 @@ def match_reprTranscript_expressionLevel( ...@@ -210,6 +210,7 @@ def match_reprTranscript_expressionLevel(
representative transcipt representative transcipt
intemediate_file (str) : txt file containing genes, transcript intemediate_file (str) : txt file containing genes, transcript
and their expression level from the transkript_extractor function and their expression level from the transkript_extractor function
output_path : path indicating were the tsv file should be written
Returns: Returns:
tsv file of representative trasncripts and their expression level tsv file of representative trasncripts and their expression level
...@@ -221,10 +222,10 @@ def match_reprTranscript_expressionLevel( ...@@ -221,10 +222,10 @@ def match_reprTranscript_expressionLevel(
df_geneTrans = transcripts_by_gene_inDf(df_intermediate) df_geneTrans = transcripts_by_gene_inDf(df_intermediate)
df_exprTrans = tsv_or_csv_to_df(exprTrans) df_exprTrans = tsv_or_csv_to_df(exprTrans)
df_reprTrans = dict_reprTrans_to_df(dict_reprTrans) df_reprTrans = dict_reprTrans_to_df(dict_reprTrans)
df_exprLevel_byGene = exprLevel_byGene(df_exprTrans, df_geneTrans) df_exprLevel_byGene = exprLevel_byGene(df_exprTrans, df_geneTrans)
df_match = match_byGene(df_reprTrans, df_exprLevel_byGene) df_match = match_byGene(df_reprTrans, df_exprLevel_byGene)
output = output_tsv(df_match) df_match.rename(columns = {'reprTrans':'id', 'Expression_level':'level'}, inplace = True)
return output return df_match
# run the programm # run the programm
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment