<commit_before>"""
wrappers around samtools
"""
import sh
from bipy.utils import replace_suffix, append_stem, is_pair
from bcbio.utils import file_exists
from bcbio.distributed.transaction import file_transaction, _flatten_plus_safe
import os
import pysam
from itertools import izip
from bipy.pipeline.stages import AbstractStage


def bam2sam(in_file, out_file=None):
    """ convert a BAM file to a SAM file """
    if is_sam(in_file):
        return in_file

    if out_file is None:
        out_file = replace_suffix(in_file, "sam")

    if file_exists(out_file):
        return out_file

    with file_transaction(out_file) as tmp_out_file:
        sh.samtools.view(in_file, _out=tmp_out_file)

    return out_file


def is_sam_or_bam(in_file):
    return is_bam(in_file) or is_sam(in_file)
<commit_msg>Added sam header to bam2sam conversion.<commit_after>"""
wrappers around samtools
"""
import sh
from bipy.utils import replace_suffix, append_stem, is_pair
from bcbio.utils import file_exists
from bcbio.distributed.transaction import file_transaction, _flatten_plus_safe
import os
import pysam
from itertools import izip
from bipy.pipeline.stages import AbstractStage


def bam2sam(in_file, out_file=None):
    """ convert a BAM file to a SAM file """
    if is_sam(in_file):
        return in_file

    if out_file is None:
        out_file = replace_suffix(in_file, "sam")

    if file_exists(out_file):
        return out_file

    with file_transaction(out_file) as tmp_out_file:
        sh.samtools.view(in_file, "-h", _out=tmp_out_file)

    return out_file


def is_sam_or_bam(in_file):
    return is_bam(in_file) or is_sam(in_file)

{'fraction_non_alphanumeric': 0.07342233009708737, 'fraction_numerical': 0.0018203883495145632, 'mean_word_length': 4.234920634920635, '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': '189891', 'n_tokens_mistral': 582, 'n_tokens_neox': 561, 'n_words': 152}