<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import argparse
import shutil
import subprocess
from natsort import natsorted
import funannotate.library as lib
from Bio import SeqIO


def runSubprocess(cmd, dir):
    proc = subprocess.Popen(
        cmd, cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate()
    if stdout:
        print(stdout)


def runtbl2asn(folder, template, discrepency, organism, isolate, strain, parameters, version):
    '''
    function to run NCBI tbl2asn
    '''
    # get funannotate version
    fun_version = lib.get_version()
    # input should be a folder
    if not os.path.isdir(folder):
        print(("tbl2asn error: %s is not a directory, exiting" % folder))
        sys.exit(1)
    # based on organism, isolate, strain, construct meta info for -j flag
    if not organism:
        print("tbl2asn error: organism not specified")
        sys.exit(1)
    meta = "[organism=" + organism + "]"
    if isolate:
        isolate_meta = "[isolate=" + isolate + "]"
        meta = meta + " " + isolate_meta
    if strain:
        strain_meta = "[strain=" + strain + "]"
        meta = meta + " " + strain_meta
    cmd = ['tbl2asn', '-y', '"Annotated using '+fun_version+'"', '-N',
           str(version), '-p', folder, '-t', template, '-M', 'n', '-Z', discrepency, '-j', '"'+meta+'"', '-V', 'b', '-c', 'fx', '-T', '-a', 'r10u']
    # check for custom parameters
    if parameters:
        params = parameters.split(' ')
        cmd = cmd + params
    runSubprocess(cmd, '.')
    return ' '.join(cmd)


def locustagGB(input):
    tag = []
    with open(input, 'r') as infile:
        for record in SeqIO.parse(infile, 'genbank'):
            for f in record.features:
                if f.type == 'gene':
                    locusTag, ID, Parent = lib.getID(f, f.type)
                    tag.append(locusTag)
                    break
    return tag[0].split('_', -1)[0]<commit_msg>add paired in option<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import argparse
import shutil
import subprocess
from natsort import natsorted
import funannotate.library as lib
from Bio import SeqIO


def runSubprocess(cmd, dir):
    proc = subprocess.Popen(
        cmd, cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = proc.communicate()
    if stdout:
        print(stdout)


def runtbl2asn(folder, template, discrepency, organism, isolate, strain, parameters, version):
    '''
    function to run NCBI tbl2asn
    '''
    # get funannotate version
    fun_version = lib.get_version()
    # input should be a folder
    if not os.path.isdir(folder):
        print(("tbl2asn error: %s is not a directory, exiting" % folder))
        sys.exit(1)
    # based on organism, isolate, strain, construct meta info for -j flag
    if not organism:
        print("tbl2asn error: organism not specified")
        sys.exit(1)
    meta = "[organism=" + organism + "]"
    if isolate:
        isolate_meta = "[isolate=" + isolate + "]"
        meta = meta + " " + isolate_meta
    if strain:
        strain_meta = "[strain=" + strain + "]"
        meta = meta + " " + strain_meta
    cmd = ['tbl2asn', '-y', '"Annotated using '+fun_version+'"', '-N',
           str(version), '-p', folder, '-t', template, '-M', 'n', '-Z', discrepency, '-j', '"'+meta+'"', '-V', 'b', '-c', 'fx', '-T', '-a', 'r10u', '-l', 'paired-ends']
    # check for custom parameters
    if parameters:
        params = parameters.split(' ')
        cmd = cmd + params
    runSubprocess(cmd, '.')
    return ' '.join(cmd)


def locustagGB(input):
    tag = []
    with open(input, 'r') as infile:
        for record in SeqIO.parse(infile, 'genbank'):
            for f in record.features:
                if f.type == 'gene':
                    locusTag, ID, Parent = lib.getID(f, f.type)
                    tag.append(locusTag)
                    break
    return tag[0].split('_', -1)[0]
{'fraction_non_alphanumeric': 0.14820359281437126, 'fraction_numerical': 0.006487025948103792, 'mean_word_length': 2.467993079584775, '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': '6865638', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1272, 'n_words': 376}