Skip to content

Commit

Permalink
json_command
Browse files Browse the repository at this point in the history
  • Loading branch information
zprobot committed Nov 9, 2023
1 parent 911d9f3 commit 5d2c5df
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from quantms_io.core.tools import convert_to_json
import click
import os
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])


@click.group(context_settings=CONTEXT_SETTINGS)
def cli():
"""
This is the main tool that gives access to all commands.
"""


@click.command("convert_tsv_to_json", short_help="Register the file to project.json.",)
@click.option("--file", help="AE or DE file", required=True)
@click.pass_context
def convert_tsv_to_json(ctx,file):
if not os.path.exists(file):
raise click.UsageError("The file does not exist.")

convert_to_json(file)

cli.add_command(convert_tsv_to_json)
if __name__ == '__main__':
cli()
2 changes: 1 addition & 1 deletion python/quantmsio/quantms_io/core/ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AbsoluteExpressionHander:
#INFO=<ID=ibaq, Number=1, Type=Float, Description="Intensity based absolute quantification">
#INFO=<ID=ribaq, Number=1, Type=Float, Description="relative iBAQ">\n"""

ABSOLUTE_EXPRESSION_EXTENSION = ".ae.absolute.tsv"
ABSOLUTE_EXPRESSION_EXTENSION = ".absolute.tsv"

def __init__(self):
self.ibaq_df = None
Expand Down
2 changes: 1 addition & 1 deletion python/quantmsio/quantms_io/core/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DifferentialExpressionHandler:
#INFO=<ID=adj.pvalue, Number=1, Type=Double, Description="P-values adjusted among all the proteins in the specific comparison using the approach by Benjamini and Hochberg">
#INFO=<ID=issue, Number=1, Type=String, Description="Issue column shows if there is any issue for inference in corresponding protein and comparison">\n"""

DIFFERENTIAL_EXPRESSION_EXTENSION = ".de.differential.tsv"
DIFFERENTIAL_EXPRESSION_EXTENSION = ".differential.tsv"

def __init__(self):
"""
Expand Down
11 changes: 8 additions & 3 deletions python/quantmsio/quantms_io/core/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""
import os
import re
import json

import pandas as pd
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -374,11 +375,15 @@ def convert_to_json(file_path):
table,content = load_de_or_ae(file_path)
output = {}
pattern = r'[\\|\|//|/]'
output['id'] = re.split(pattern,file_path)[-1]
file_name = re.split(pattern,file_path)[-1]
output['id'] = file_name
output['metadata'] = content
records = {}
for col in table.columns:
records[col] = table.loc[:,col].to_list()
output['records'] = records

return output
b = json.dumps(output)
output_path = ".".join(file_name.split('.')[:-1]) + '.json'
f = open(output_path, 'w')
f.write(b)
f.close()

0 comments on commit 5d2c5df

Please sign in to comment.