<commit_before>#!/usr/bin/env python
# rebatch.py
# 
#   Copyright (C) 2011 <NAME>, <NAME>
#
#   This code is distributed under the BSD license, a copy of which is 
#   included in the root directory of this package.
# 
# Replacement for CCP4 program rebatch, using cctbx Python.
# 

import os
import sys

from iotbx import mtz
from cctbx.array_family import flex

def rebatch(hklin, hklout, blah):
    '''Need to implement: include batch range, exclude batches, add N to
    batches, start batches at N.'''

    mtz_obj = mtz.object(file_name = hklin)
    
    batch_column = None
    batch_dataset = None

    for crystal in mtz_obj.crystals():
        for dataset in crystal.datasets():
            for column in dataset.columns():
                if column.label() == 'BATCH':
                    batch_column = column
                    batch_dataset = dataset

    if not batch_column:
        raise RuntimeError, 'no BATCH column found in %s' % hklin

    batch_column_values = batch_column.extract_values(
        not_a_number_substitute = -1)

    valid = flex.bool()

    # modify batch columns

    # done modifying
    
    batch_column.set_values(values = batch_column_values,
                            selection_valid = valid)

    # and write this lot out as hklout
    
    mtz_obj.write(file_name = hklout)
<commit_msg>Have reached point of being able to modify batch numbers<commit_after>#!/usr/bin/env python
# rebatch.py
# 
#   Copyright (C) 2011 <NAME>, <NAME>
#
#   This code is distributed under the BSD license, a copy of which is 
#   included in the root directory of this package.
# 
# Replacement for CCP4 program rebatch, using cctbx Python.
# 

import os
import sys

from iotbx import mtz
from cctbx.array_family import flex

def rebatch(hklin, hklout, first_batch):
    '''Need to implement: include batch range, exclude batches, add N to
    batches, start batches at N.'''

    mtz_obj = mtz.object(file_name = hklin)

    batch_column = None
    batch_dataset = None

    for crystal in mtz_obj.crystals():
        for dataset in crystal.datasets():
            for column in dataset.columns():
                if column.label() == 'BATCH':
                    batch_column = column
                    batch_dataset = dataset

    if not batch_column:
        raise RuntimeError, 'no BATCH column found in %s' % hklin

    batch_column_values = batch_column.extract_values(
        not_a_number_substitute = -1)

    valid = flex.bool()

    # modify batch columns, and also the batch headers

    if first_batch != None:
        offset = first_batch - min(batch_column_values)
        batch_column_values = batch_column_values + offset

        for batch in mtz_obj.batches():
            batch.set_num(int(batch.num() + offset))
            
    # done modifying
    
    batch_column.set_values(values = batch_column_values,
                            selection_valid = valid)

    # and write this lot out as hklout
    
    mtz_obj.write(file_name = hklout)

if __name__ == '__main__':

    import sys

    hklin = sys.argv[1]
    hklout = 'arse.mtz'

    rebatch(hklin, hklout, first_batch = 1001)
{'fraction_non_alphanumeric': 0.0792488860598345, 'fraction_numerical': 0.0054105665181413114, 'mean_word_length': 2.484478935698448, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5867749', 'n_tokens_mistral': 1002, 'n_tokens_neox': 936, 'n_words': 304}