<commit_before>import sys
results = {}
with open(sys.argv[1]) as screen_results:
    for line in screen_results:
        fields = line.strip().split()
        if len(fields) and fields[0][0] != '#' and fields[0] != 'Library':
            if fields[0] == '%Hit_no_libraries:':
                results['unmapped'] = int(float(fields[1]) / 100.0 * results['no_reads'])
                continue
            results[fields[0] + '_single'] = int(fields[4])
            results[fields[0] + '_multiple'] = int(fields[6])
            results['no_reads'] = int(fields[1])
header = ['Mouse_single', 'Mouse_multiple', 'Human', 'Other', 'Unmapped']
data = [results['Mouse_single'],
        results['Mouse_multiple'],
        results['Human_single'] + results['Human_multiple']]
data.append(results['no_reads'] - sum(data) - results['unmapped'])
data.append(results['unmapped'])
print '\t'.join(header)
print '\t'.join(map(lambda i:str(i / float(sum(data))),data))<commit_msg>Improved script to extract contamination from fastqscreen<commit_after>import sys
import os

header = ['Mouse_single', 'Mouse_multiple', 'Human', 'Other', 'Unmapped']
print '\t'.join(header)
for fi in sys.argv[1:]:
    sample = os.path.basename(fi).split('.')[0]
    with open(fi) as screen_results:
        results = {}
        for line in screen_results:
            fields = line.strip().split()
            if len(fields) and fields[0][0] != '#' and fields[0] != 'Library':
                if fields[0] == '%Hit_no_libraries:':
                    results['unmapped'] = int(float(fields[1]) / 100.0 * results['no_reads'])
                    continue
                results[fields[0] + '_single'] = int(fields[4])
                results[fields[0] + '_multiple'] = int(fields[6])
                results['no_reads'] = int(fields[1])
    data = [results['Mouse_single'],
            results['Mouse_multiple'],
            results['Human_single'] + results['Human_multiple']]
    data.append(results['no_reads'] - sum(data) - results['unmapped'])
    data.append(results['unmapped'])
    data = map(lambda i:str(i / float(sum(data))),data)
    data = [sample] + data
    print '\t'.join(data)
{'fraction_non_alphanumeric': 0.1780250347705146, 'fraction_numerical': 0.014371812702828002, 'mean_word_length': 3.094876660341556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4298778', 'n_tokens_mistral': 691, 'n_tokens_neox': 662, 'n_words': 132}