Mercurial > repos > czouaoui > abundance_table_to_biom1
changeset 1:10eedb4b587f draft
Deleted selected files
author | czouaoui |
---|---|
date | Tue, 20 Mar 2018 04:25:37 -0400 |
parents | 5ac3be5b1d12 |
children | 613e054cad7f |
files | abundanceTable_to_biom/abundanceTable_to_biom.py~ abundanceTable_to_biom/abundanceTable_to_biom.xml abundanceTable_to_biom/abundanceTable_to_biom.xml~ |
diffstat | 3 files changed, 0 insertions(+), 110 deletions(-) [+] |
line wrap: on
line diff
--- a/abundanceTable_to_biom/abundanceTable_to_biom.py~ Tue Mar 20 04:21:57 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -import datetime -import argparse -import csv -import json - -def __main__(): - print "Generating biom file ..." - options = argsParser() - families, samples, data = abundanceTableParser(options.file) - biom_file = constructBiom(families, samples, data) - file_name = options.out_name + '.biom' if options.out_name else 'result.biom' - with open(file_name, 'w') as output: - json.dump(biom_file, output) - print "Your biom file (" + file_name + ") is now created" - -def argsParser(): - parser = argparse.ArgumentParser() - parser.add_argument("-f", "--file", type=argparse.FileType('r'), help="Abundance table in csv format") - parser.add_argument("-o", "--out_name", help="BIOM (v1.0) file name") - - return parser.parse_args() - -def abundanceTableParser(file): - with file: - reader = csv.reader(file) - - families = [] - for i, row in enumerate(reader): - if i != 0: - families.append({"id":"OTU_" + str(i), "metadata":{"taxonomy":["k__", "p__", "c__", "o__", - "f__" + row[0], "g__", "s__"]}}) - - file.seek(0) - first_row = next(reader) - samples = [] - for i in range(1, len(first_row)): - samples.append({"id":first_row[i], "metadata":{"phinchID":first_row[i]}}) - - file.seek(0) - data = [] - for i, row in enumerate(reader): - if i != 0: - for j in range(1, len(row)): - if row[j] != 'NA': - data.append([i - 1, j - 1, int(row[j])]) - - return families, samples, data - -def constructBiom(families, samples, data): - biom = {"id":"null", - "format": "Biological Observation Matrix 0.9.1-dev", - "format_url": "http://biom-format.org/documentation/format_versions/biom-1.0.html", - "type": "OTU table", - "generated_by": "abundanceTable_to_biom script", - "date": datetime.date.today().isoformat(), - "matrix_type": "sparse", - "matrix_element_type": "int", - "shape": [len(families), len(samples)], - "rows":families, - "columns":samples, - "data":data} - return biom - - -if __name__ == "__main__": - __main__()
--- a/abundanceTable_to_biom/abundanceTable_to_biom.xml Tue Mar 20 04:21:57 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -<tool id="abundanceTable_to_biom" name="Converting abundance tables to Biom files (v1.0)" version="0.1.0"> - <command detect_errors="exit_code"><![CDATA[ - python $__tool_directory__/abundanceTable_to_biom.py --file $input --out_name biom_result - ]]></command> - <inputs> - <param type="data" name="input" format="csv" label="Abundance table"/> - </inputs> - <outputs> - <data name= "output" format="biom" label="${input.name} to Biom (v1.0)" from_work_dir="biom_result.biom"/> - </outputs> - <tests> - <test> - <param name="input" format="csv" value="merge_summary_reads.csv"/> - <output name="output" format="biom" file="biom_result.biom"/> - </test> - </tests> - <help><![CDATA[ - This tool is used to generate a Biom file (v1.0) from an abundance table. - The first column of the header is a taxonomy list (families). Next columns contain sample ids. - The abundancy of reads is set inside the table. - ]]></help> -</tool>
--- a/abundanceTable_to_biom/abundanceTable_to_biom.xml~ Tue Mar 20 04:21:57 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -<tool id="abundanceTable_to_biom" name="Converting abundance tables to Biom files (v1.0)" version="0.1.0"> - <command detect_errors="exit_code"><![CDATA[ - python $__tool_directory__/abundanceTable_to_biom.py --file $input --out_name biom_result - ]]></command> - <inputs> - <param type="data" name="input" format="csv" label="Abundance table"/> - </inputs> - <outputs> - <data name= "output" format="biom" label="${input.name} to Biom (v1.0)" from_work_dir="biom_result.biom"/> - </outputs> - <tests> - <test> - <param name="input" format="csv" value="merge_summary_reads.csv"/> - <output name="output" format="biom" file="biom_result.biom"/> - </test> - </tests> - <help><![CDATA[ - This tool is used to generate a Biom file (v1.0) from an abundance table. - The first column of the header is a taxonomy list (families). Next columns contain sample ids. - The abundancy of reads is set inside the table. - ]]></help> -</tool>