<commit_before>#!/matta1/biotools/anaconda/bin/python


# script to get id: full description from the fasta file (swissprot, nr, ...)
# usage: grep ">" uniprot_sprot.fasta | fastaID2names.py > sprot_id2Name.txt


import sys

for line in sys.stdin:
    if line.startswith(">"):
        entry = line.rstrip().split(" ", 1)
        ID = entry[0][1:]
	    name = entry[1]
        sys.stdout.write( ID + "\t" + name + '\n')

sys.stdin.close()
sys.stdout.close()
sys.exit()

<commit_msg>modified fastaID2names to count length of the fasta entries<commit_after>#!/matta1/biotools/anaconda/bin/python

# script to get id: full description from the fasta file (swissprot, nr, ...)
# update: now gets length of fasta entry as well. Note, this is *protein* length (# amino acids)

#simple version, doesn't use fasta parser ---> potentially edit to use Nolan's fasta parser

import sys, argparse

parser = argparse.ArgumentParser()
parser.add_argument('--fasta', help='tab-separated database lookup: full name file for reference (eg nr or swissprot)')
args = parser.parse_args()


outF = open(args.fasta.split('.fa')[0] + '.id2names', 'w')

bp = 0
name =''
with open(args.fasta) as f:
    for line in f:
        if line.startswith(">"):
	    if len(name) > 0: # need to write *after* get bp len
                outF.write( ID + "\t" + name + '\t' + str(bp) + '\n')
            	bp = 0
	    entry = line.rstrip().split(" ", 1)
            ID = entry[0][1:]
	    name = entry[1]
        else:
            bp = bp + len(line.rstrip())
    #catch last contig
    outF.write( ID + "\t" + name + '\t' + str(bp) + '\n')

    outF.close()
    f.close()



{'fraction_non_alphanumeric': 0.1565749235474006, 'fraction_numerical': 0.011009174311926606, 'mean_word_length': 2.8135198135198136, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2726200', 'n_tokens_mistral': 601, 'n_tokens_neox': 565, 'n_words': 170}