Created
September 27, 2019 14:40
-
-
Save jhejderup/e2755a2d9824e3bc1c2e72690469a199 to your computer and use it in GitHub Desktop.
Parsing PITest mutations.csv
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os.path, sys, sets | |
def reformat(line): | |
return replace_slash_dot( | |
split_line( | |
remove_first_char( | |
remove_newline( | |
line)))) | |
def remove_newline(line): | |
return line.rstrip('\n') | |
def remove_first_char(line): | |
return line[1:] | |
def split_line(line): | |
return line.split('(')[0] | |
def replace_slash_dot(line): | |
return line.replace("/",".") | |
def main(mutations_file): | |
assert os.path.exists('functions.txt') | |
assert os.path.exists(mutations_file) | |
lst_fns = [reformat(line) for line in open('functions.txt')] | |
set_fns = sets.Set(lst_fns) | |
lst_mutations = [remove_newline(line) for line in open(mutations_file)] | |
dict_mutants = {}; | |
for mutant in lst_mutations: | |
arr = mutant.split(",") | |
fn = '.'.join([arr[1],arr[3]]) | |
if fn in set_fns: | |
if fn in dict_mutants: | |
dict_mutants[fn].add(mutant) | |
else: | |
dict_mutants[fn] = sets.Set([mutant]) | |
f= open("mutations.csv","w+") | |
for fn, mutants in dict_mutants.items(): | |
size = 0.0 | |
counter = 0.0 | |
size = len(mutants) | |
for mutant in mutants: | |
arr = mutant.split(',') | |
if arr[6] != 'none': | |
counter = counter + 1 | |
f.write("{}\t{:.2f}\n".format(fn.replace(".","/"),counter/size)) | |
for fn in set_fns: | |
if fn not in dict_mutants: | |
f.write("{}\t0\n".format(fn.replace(".","/"))) | |
f.close() | |
if __name__ == '__main__': | |
mutations_file = sys.argv[1] | |
main(mutations_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment