<commit_before>#!/usr/bin/python3

import os
import argparse
import requests

# --------------------------------------------------------------------


def desc_template_generator(desc_file, mirna_name, family_id, wiki_links=None, second_author=None, go_terms, dest_dir=None):
    """

    desc_file:
    mirna_name:
    family_id:
    wiki_links:
    dest_dir:
    return:
    """

    """
    ID   ShortName
    DE   Family description
    AU   Who RU
    SE   Where did the seed come from
    GA   25.00
    TC   30.10
    NC   24.50
    BM   cmbuild -F CM SEED
    CB   cmcalibrate --mpi CM
    SM   cmsearch --cpu 4 --verbose --nohmmonly -T 30.00 -Z 742849.287494 CM SEQDB
    """

    wk_constant = "MicroRNA"

    essential_desc_lines = {"GA": "", "TC": "", "NC": "", "BM": "", "CB": "", "SM": ""}

    if dest_dir is None:
        dest_dir = os.path.split(desc_file)[0]

    if desc_file is not None:
        fp_in = open(desc_file, 'r')
        for line in fp_in:
            if line[0:2] in essential_desc_lines:
                line = [x for x in line.strip().split(' ') if x != '']
                new_line = ' '.join(line[1:])
                essential_desc_lines[line[0]] = new_line
        fp_in.close()

    os.rename(desc_file, os.path.join(dest_dir, "DESC_old"))

    author = "Griffiths-Jones SR; 0000-0001-6043-807X"

    if second_author is not None:
        if second_author.find("<NAME>") == -1:
            author = author + '; ' + second_author

    desc_template = """ID   %s
DE   %s microRNA precursor family
AU   %s
SE   Griffiths-Jones SR
SS   Predicted; RNAalifold
GA   %s
TC   %s
NC   %s
TP   Gene; miRNA;
BM   %s
CB   %s
SM   %s
DR   MIPF; %s;
DR   URL; http://www.mirbase.org;
DR   SO; 0001244; pre_miRNA;
"""
    desc_bottom_half="""
CC   This family represents the microRNA (miRNA) precursor %s
CC   imported from miRBase.
WK   %s
"""

    fp_out = open(os.path.join(dest_dir, "DESC"), 'w')

    wiki_link = wk_constant

    if family_id in wiki_links:
        wiki_link = wiki_links[family_id]

    # write DESC upper half
    fp_out.write(desc_template % (mirna_name, mirna_name, author, essential_desc_lines["GA"],
                                  essential_desc_lines["TC"], essential_desc_lines["NC"],
                                  essential_desc_lines["BM"], essential_desc_lines["CB"],
                                  essential_desc_lines["SM"], family_id))

    # write GO terms if any
    if go_terms is not None:
        for go_term_string in go_terms.keys():
            fp_out.write("DR   %s\n" % go_term_string)
            
    # write DESC bottom half
    fp_out.write(desc_bottom_half % (mirna_name, wiki_link))

    fp_out.close()<commit_msg>Fixes argument order error<commit_after>#!/usr/bin/python3

import os
import argparse
import requests

# --------------------------------------------------------------------


def desc_template_generator(desc_file, mirna_name, family_id, wiki_links=None, second_author=None, go_terms=None, dest_dir=None):
    """

    desc_file:
    mirna_name:
    family_id:
    wiki_links:
    dest_dir:
    return:
    """

    """
    ID   ShortName
    DE   Family description
    AU   Who RU
    SE   Where did the seed come from
    GA   25.00
    TC   30.10
    NC   24.50
    BM   cmbuild -F CM SEED
    CB   cmcalibrate --mpi CM
    SM   cmsearch --cpu 4 --verbose --nohmmonly -T 30.00 -Z 742849.287494 CM SEQDB
    """

    wk_constant = "MicroRNA"

    essential_desc_lines = {"GA": "", "TC": "", "NC": "", "BM": "", "CB": "", "SM": ""}

    if dest_dir is None:
        dest_dir = os.path.split(desc_file)[0]

    if desc_file is not None:
        fp_in = open(desc_file, 'r')
        for line in fp_in:
            if line[0:2] in essential_desc_lines:
                line = [x for x in line.strip().split(' ') if x != '']
                new_line = ' '.join(line[1:])
                essential_desc_lines[line[0]] = new_line
        fp_in.close()

    os.rename(desc_file, os.path.join(dest_dir, "DESC_old"))

    author = "<NAME>; 0000-0001-6043-807X"

    if second_author is not None:
        if second_author.find("<NAME>") == -1:
            author = author + '; ' + second_author

    desc_template = """ID   %s
DE   %s microRNA precursor family
AU   %s
SE   Griffiths-Jones SR
SS   Predicted; RNAalifold
GA   %s
TC   %s
NC   %s
TP   Gene; miRNA;
BM   %s
CB   %s
SM   %s
DR   MIPF; %s;
DR   URL; http://www.mirbase.org;
DR   SO; 0001244; pre_miRNA;
"""
    desc_bottom_half="""
CC   This family represents the microRNA (miRNA) precursor %s
CC   imported from miRBase.
WK   %s
"""

    fp_out = open(os.path.join(dest_dir, "DESC"), 'w')

    wiki_link = wk_constant

    if family_id in wiki_links:
        wiki_link = wiki_links[family_id]

    # write DESC upper half
    fp_out.write(desc_template % (mirna_name, mirna_name, author, essential_desc_lines["GA"],
                                  essential_desc_lines["TC"], essential_desc_lines["NC"],
                                  essential_desc_lines["BM"], essential_desc_lines["CB"],
                                  essential_desc_lines["SM"], family_id))

    # write GO terms if any
    if go_terms is not None:
        for go_term_string in go_terms.keys():
            fp_out.write("DR   %s\n" % go_term_string)

    # write DESC bottom half
    fp_out.write(desc_bottom_half % (mirna_name, wiki_link))

    fp_out.close()
{'fraction_non_alphanumeric': 0.14163885799035966, 'fraction_numerical': 0.021505376344086023, 'mean_word_length': 2.0828571428571427, 'pattern_counts': {'":': 12, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1773886', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1812, 'n_words': 469}