<commit_before># ----------------------------------------------------------------------------
# Copyright (c) 2015--, The WGS-HGT Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------

#
# Parse output files of GI tools.
#

import sys
import click
from skbio import Sequence


def parse_output_gi(genbank_fp,
                    gi_fp):
    """ Identify genes contained in GIs

    Parameters
    ----------
    genbank_fp: string
        file path to genome in GenBank format
    gi_fp: string
        file path to GI list

    Returns
    -------
    output: string
        gene names (protein_ids) separated by newline
    """
    genes = {}
    gb = Sequence.read(genbank_fp, format='genbank')
    for feature in gb.interval_metadata.features:
        if feature['type_'] == 'CDS':
            if 'protein_id' not in feature:
                continue
            protein_id = feature['protein_id'].replace('\"', '')
            loc = feature['location']
            if loc.startswith('complement'):
                loc = loc[11:-1]
            (start, end) = (int(x.strip('<>')) for x in loc.split('..'))
            if protein_id not in genes:
                genes[protein_id] = [start, end]
            else:
                raise KeyError("Duplicate protein ID: %s" % protein_id)
    genes_in_gi = {}
    with open(gi_fp, 'r') as input_f:
        for line in input_f:
            l = line.strip().split()
            if len(l) < 2:
                continue
            (start, end) = (int(l[0]), int(l[1]))
            for (gene, l) in genes.items():
                if (l[0] >= start and l[1] <= end):
                    if gene not in genes_in_gi:
                        genes_in_gi[gene] = 1
    output = []
    for gene in sorted(genes_in_gi):
        output.append(gene)
    return '\n'.join(output)


@click.command()
@click.option('--genbank-fp', required=True,<commit_msg>Update parse_output_gi.py<commit_after># ----------------------------------------------------------------------------
# Copyright (c) 2015--, The WGS-HGT Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
# ----------------------------------------------------------------------------

#
# Parse output files of GI tools.
#

import sys
import click
from skbio import Sequence


def parse_output_gi(genbank_fp,
                    gi_fp):
    """ Identify genes contained in GIs

    Parameters
    ----------
    genbank_fp: string
        file path to genome in GenBank format
    gi_fp: string
        file path to GI list

    Returns
    -------
    output: string
        gene names (protein_ids) separated by newline
    """
    genes = {}
    gb = Sequence.read(genbank_fp, format='genbank')
    for feature in gb.metadata['FEATURES']:
        if feature['type_'] == 'CDS':
            if 'protein_id' not in feature:
                continue
            protein_id = feature['protein_id'].replace('\"', '')
            loc = feature['location']
            if loc.startswith('complement'):
                loc = loc[11:-1]
            (start, end) = (int(x.strip('<>')) for x in loc.split('..'))
            if protein_id not in genes:
                genes[protein_id] = [start, end]
            else:
                raise KeyError("Duplicate protein ID: %s" % protein_id)
    genes_in_gi = {}
    with open(gi_fp, 'r') as input_f:
        for line in input_f:
            l = line.strip().split()
            if len(l) < 2:
                continue
            (start, end) = (int(l[0]), int(l[1]))
            for (gene, l) in genes.items():
                if (l[0] >= start and l[1] <= end):
                    if gene not in genes_in_gi:
                        genes_in_gi[gene] = 1
    output = []
    for gene in sorted(genes_in_gi):
        output.append(gene)
    return '\n'.join(output)


@click.command()
@click.option('--genbank-fp', required=True,
{'fraction_non_alphanumeric': 0.18912415784408085, 'fraction_numerical': 0.006256015399422521, 'mean_word_length': 1.5224514563106797, 'pattern_counts': {'":': 0, '<': 9, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3801262', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1140, 'n_words': 346}