<commit_before>import numpy as np
import numpy.ma as ma
import scipy as sp
import scipy.stats
import scipy.special
import matplotlib as mpl
import matplotlib.pyplot as plt

import vdj


def clone_timeseries(inhandle,time_tags):
    time_tags_set = set(time_tags)
    clone_counts = {}
    for tag in time_tags:
        clone_counts[tag]={}
    for chain in vdj.parse_VDJXML(inhandle):
        try: clone_counts[(chain.tags&time_tags_set).pop()][vdj.get_clone(chain)] += 1
        except KeyError: clone_counts[(chain.tags&time_tags_set).pop()][vdj.get_clone(chain)] = 1
    
    
    
    
    
    
    



def reps2timeseries(reps,refclusters):
	"""Return time series matrix from list or Repertoire objs in chron order.
	
	reps is list of Repertoire objects
	refclusters is the master list of reference clusters
	"""
	numreps = len(reps)
	numclusters = len(refclusters)
	
	countdata = np.zeros((numclusters,numreps))
	for (i,rep) in enumerate(reps):
		clusters = vdj.getClusters(rep)
		countdata[:,i] = vdj.countsClusters(clusters,refclusters)
	
	return countdata







def scatter_repertoires_ontology(reps,info='VJCDR3',gooddata=False,measurement='proportions'):
	"""Create a grid of scatter plots showing corelations between all pairs of repertoires.
	
	reps -- list of Repertoire objects
	
	"""
	numreps = len(reps)<commit_msg>Finished time-series fn<commit_after>import numpy as np
import numpy.ma as ma
import scipy as sp
import scipy.stats
import scipy.special
import matplotlib as mpl
import matplotlib.pyplot as plt

import vdj


def clone_timeseries(inhandle,time_tags,reference_clones=None):
    # get count data
    time_tags_set = set(time_tags)
    clone_counts = {}
    for tag in time_tags:
        clone_counts[tag]={}
    for chain in vdj.parse_VDJXML(inhandle):
        try:
            curr_time_tag = (chain.tags&time_tags_set).pop()
        except KeyError:
            continue    
        
        try:
            clone_counts[curr_time_tag][vdj.get_clone(chain)] += 1
        except KeyError:
            clone_counts[curr_time_tag][vdj.get_clone(chain)] = 1
    
    # set up reference clones
    if reference_clones == None:
        reference_clones = set()
        for counts in clone_counts.itervalues():
            reference_clones.update(counts.keys())
        reference_clones = list(reference_clones)
    
    # build timeseries matrix
    num_clones = len(reference_clones)
    num_times = len(time_tags)
    countdata = np.zeros((num_clones,num_times))
    for (i,tag) in enumerate(time_tags):
        countdata[:,i] = vdj.counts_clones_counts(clone_counts[tag],reference_clones)
    
    return countdata







def scatter_repertoires_ontology(reps,info='VJCDR3',gooddata=False,measurement='proportions'):
	"""Create a grid of scatter plots showing corelations between all pairs of repertoires.
	
	reps -- list of Repertoire objects
	
	"""
	numreps = len(reps)
{'fraction_non_alphanumeric': 0.09097174362508614, 'fraction_numerical': 0.002412129565816678, 'mean_word_length': 3.543035993740219, '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': '4456520', 'n_tokens_mistral': 1021, 'n_tokens_neox': 974, 'n_words': 225}