Commit 41b25020 authored by Marc Duez's avatar Marc Duez

fastaToJson.py : repair/update > python script, used to produce germline.js...

fastaToJson.py : repair/update > python script, used to produce germline.js with fasta file from germline folder
parent e1e60c5b
...@@ -3,47 +3,55 @@ import json ...@@ -3,47 +3,55 @@ import json
import sys import sys
import time import time
if len(sys.argv) < 2: if len(sys.argv) < 2:
print "Usage: %s <FASTA input file> [JSON output file]" % sys.argv[0] print "Usage: %s <FASTA input file> [JSON output file]" % sys.argv[0]
sys.exit() sys.exit()
input_name = sys.argv[1] input_name = sys.argv[1]
output_name = "" output_name = ""
if len(sys.argv) == 3: if len(sys.argv) >= 3:
output_name = sys.argv[2] output_name = sys.argv[-1]
fasta = open(sys.argv[1], "r")
table = {} table = {}
identifiant = "" identifiant = ""
sequence = "" sequence = ""
for ligne in fasta :
ligne = ligne.rstrip('\n\r')
if len(ligne) != 0 :
if ligne[0]=='>' :
if len(sequence)!=0 :
table[identifiant]=sequence
identifiant=ligne[1:]
if identifiant.count('|') != 0 :
tmp=identifiant.split('|')
identifiant=tmp[1]
if identifiant.count('_') != 0 :
tmp2=identifiant.split('_')
identifiant=tmp2[0]
sequence="";
else :
sequence+=ligne
if len(sequence)!=0 :
table[identifiant]=sequence
fasta.close() for i in range(1, len(sys.argv)-1) :
print json.dumps(table, indent=2, sort_keys=True) fasta = open(sys.argv[i], "r")
if output_name != "": system = sys.argv[i].split('/')[-1].split('.')[0]
with open(output_name, "w") as file :
json.dump(table, file, indent=2, sort_keys=True) table[system] = {}
for ligne in fasta :
ligne = ligne.rstrip('\n\r')
if len(ligne) != 0 :
if ligne[0]=='>' :
if len(sequence)!=0 :
table[system][identifiant]=sequence
identifiant=ligne[1:]
if identifiant.count('|') != 0 :
tmp=identifiant.split('|')
identifiant=tmp[1]
if identifiant.count('_') != 0 :
tmp2=identifiant.split('_')
identifiant=tmp2[0]
sequence="";
else :
sequence+=ligne
if len(sequence)!=0 :
table[system][identifiant]=sequence
fasta.close()
if output_name != "":
with open(output_name, "w") as file :
file.write("germline = ")
json.dump(table, file, indent=2, sort_keys=True)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment