<commit_before>#!/usr/bin/env python
"""
Created on April 20 2014
Updated on April 13 2016
@author: <NAME>, <EMAIL>, <NAME>. Dinner Group, University of Chicago

This script is one in a series of scripts for running empirical JTK_CYCLE analysis as described in 

Hutchison, Maienschein-Cline, and Chiang et al. Improved statistical methods enable greater sensitivity in rhythm detection for genome-wide data, PLoS Computational Biology 2015 11(3): e 1004094. doi:10.1371/journal.pcbi.1004094

It is a sped-up version of the original provided script using reference waveform pre-calculation and symmetry arguments to reduce computational time.

The resulting *jtkout.txt file contains only the best-matching waveform for each time series (unlike the original script).
Please use ./jtk7.py -h to see the help screen for further instructions on running this script.

"""
VERSION="1.1"

#from scipy.stats import kendalltau
import numpy as np
import argparse
import os.path


from accessories import get_waveform_list as a_get_waveform_list
from accessories import make_references as a_make_references
from accessories import kt ### this is kendall tau
from accessories import get_matches as a_get_matches
from accessories import pick_best_match as a_pick_best_match
from accessories import get_best_match as a_get_best_match
#from operator import itemgetter
#import sys
#import itertools as it
#import time
#from scipy.stats import norm

def main(args):
    fn          = args.filename
    prefix      = args.prefix
    fn_waveform = args.waveform
    fn_period   = args.period
    fn_phase    = args.phase
    fn_width    = args.width
    fn_null     = args.null
    fn_out      = args.output

    fn_out        = set_fn_out(fn,prefix,fn_out)
    fnw = fn_waveform.split('/')[-1] if '/' in fn_waveform else fn_waveform
    if 'trough' in fnw:
        waveform = 'trough'
    else:
        waveform = 'cosine'

        
    periods       = np.array(read_in_list(fn_period),dtype=float)
    phases        = np.array(read_in_list(fn_phase),dtype=float)
    widths        = np.array(read_in_list(fn_width),dtype=float)
    header,series   = read_in(fn)
    #header,series = organize_data(header,data)
    out_lines = [[]]*len(series)
    #print periods
    #print phases
    #print widths
    ##### Here we insert some code to allow for a speedup if full set of phases and asymmetries are used
    #if len(phases)==len(widths)+1:
    #if 
    
    triples = a_get_waveform_list(periods,phases,widths)
    print triples

    
    new_header = [float(x[2:]) for x in header]
    dref = a_make_references(new_header,triples,waveform)
    print dref.keys()
    for i,serie in enumerate(series):<commit_msg>Enabled CT, ZT, or no prefix to be used for header times<commit_after>#!/usr/bin/env python
"""
Created on April 20 2014
Updated on April 13 2016
@author: <NAME>, <EMAIL>, <NAME>, University of Chicago

This script is one in a series of scripts for running empirical JTK_CYCLE analysis as described in 

Hutchison, Maienschein-Cline, and Chiang et al. Improved statistical methods enable greater sensitivity in rhythm detection for genome-wide data, PLoS Computational Biology 2015 11(3): e 1004094. doi:10.1371/journal.pcbi.1004094

It is a sped-up version of the original provided script using reference waveform pre-calculation and symmetry arguments to reduce computational time.

The resulting *jtkout.txt file contains only the best-matching waveform for each time series (unlike the original script).
Please use ./jtk7.py -h to see the help screen for further instructions on running this script.

"""
VERSION="1.1"

#from scipy.stats import kendalltau
import numpy as np
import argparse
import os.path


from accessories import get_waveform_list as a_get_waveform_list
from accessories import make_references as a_make_references
from accessories import kt ### this is kendall tau
from accessories import get_matches as a_get_matches
from accessories import pick_best_match as a_pick_best_match
from accessories import get_best_match as a_get_best_match
#from operator import itemgetter
#import sys
#import itertools as it
#import time
#from scipy.stats import norm

def main(args):
    fn          = args.filename
    prefix      = args.prefix
    fn_waveform = args.waveform
    fn_period   = args.period
    fn_phase    = args.phase
    fn_width    = args.width
    fn_null     = args.null
    fn_out      = args.output

    fn_out        = set_fn_out(fn,prefix,fn_out)
    fnw = fn_waveform.split('/')[-1] if '/' in fn_waveform else fn_waveform
    if 'trough' in fnw:
        waveform = 'trough'
    else:
        waveform = 'cosine'

        
    periods       = np.array(read_in_list(fn_period),dtype=float)
    phases        = np.array(read_in_list(fn_phase),dtype=float)
    widths        = np.array(read_in_list(fn_width),dtype=float)
    header,series   = read_in(fn)
    #header,series = organize_data(header,data)
    out_lines = [[]]*len(series)
    #print periods
    #print phases
    #print widths
    ##### Here we insert some code to allow for a speedup if full set of phases and asymmetries are used
    #if len(phases)==len(widths)+1:
    #if 
    
    triples = a_get_waveform_list(periods,phases,widths)
    #print triples
    
    
    new_header = [float(x[2:]) if 'ZT' in x or 'CT' in x else float(x) for x in header]
    
    dref = a_make_references(new_header,triples,waveform)

    for i,serie in enumerate(series):
{'fraction_non_alphanumeric': 0.07544052863436124, 'fraction_numerical': 0.016519823788546256, 'mean_word_length': 3.6413969335604772, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '166263', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1677, 'n_words': 574}