-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add helper_function to convert geneCluster.json into csv
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os, json | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description='convert geneCluster.json into a csv file ',\ | ||
usage=' python %(prog)s'+' -in /path/geneCluster.json -out /path/geneCluster_stats.csv') | ||
parser.add_argument('-in', '--input_filepath', type = str, required=True, help='') | ||
parser.add_argument('-out', '--output_filepath', type = str, required=True, help='') | ||
params = parser.parse_args() | ||
input_filepath=params.input_filepath | ||
output_filepath=params.output_filepath | ||
|
||
def convert_cluster_statistics_csv(input_path, output_path): | ||
with open(input_path) as inputf,\ | ||
open(output_path, 'w') as outputf: | ||
cluster_stats_list= json.load(inputf) | ||
header_list=['count','ann','dupli','GName','geneLen','event','msa','divers','geneId','allAnn','dup_detail','allGName','locus'] | ||
header_description=['#strain count','major annotation','whether duplicated','major gene name','gene length','number of gene events','clusterID','diversity','gene ID','all annotations','duplication details','all gene names','all locus tags'] | ||
outputf.write(','.join([ header for header in header_description ])) | ||
outputf.write('\n') | ||
for cluster_stats in cluster_stats_list: | ||
outputf.write(','.join([ str(cluster_stats[header]) for header in header_list ])) | ||
outputf.write('\n') | ||
|
||
convert_cluster_statistics_csv(input_filepath, output_filepath) |