<commit_before>#!/usr/bin/perl -w

#splits the uniprot xml files into separate files based on the ncbi taxon id. Reads the taxons of interest from a 
#centrally stored file. Source directory and output directory are supplied as command line args, expexts source
#files to be uniprot_sprot.xml uniprot_trembl.xml 

use strict;
use warnings;

my($start, $end, $buffer, $trigger) = ("<entry", "</entry>", '', 'type="NCBI Taxonomy"');
my ($filename, $fname_end);
my ($keep, $taxon) = ("false", '0000');
my (@new_contents, @old_contents);
my %taxons;

#the xml declaration and root element for each output file			
my $prolog = '<?xml version="1.0" encoding="UTF-8"?>
<uniprot xmlns="http://uniprot.org/uniprot"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://uniprot.org/uniprot http://www.uniprot.org/support/docs/uniprot.xsd">';
#define the last elements for each output file
my $element_end = '<copyright>
Copyrighted by the UniProt Consortium, see http://www.uniprot.org/terms
Distributed under the Creative Commons Attribution-NoDerivs License
</copyright>
</uniprot>';

#define source and output directories
my $source_dir = $ARGV[0]
    or die "\nPlease supply a directory for the source files and the destination direcory.
e.g. ./split_uniprot.pl /shared/data/uniprot/9.3/ /shared/data/uniprot/9.3/split/\n\n";

my $split_dir = $ARGV[1]
    or die "\nPlease supply a directory for the source files and the destination direcory.\n
e.g. ./split_uniprot.pl /shared/data/uniprot/9.3/ /shared/data/uniprot/9.3/split/\n\n";

#create output dir, empty it if already exists?
if(!-e $split_dir ){
	mkdir ("$split_dir", 0755) || die "Cannot mkdir newdir: $!";
}else{
	opendir(DIR,$split_dir) || die("Cannot open directory !\n");
	@old_contents=grep(!/^\.\.?$/,readdir DIR);
	closedir(DIR);
	if(@old_contents){
		print "\n!!$split_dir is not empty!!\nDo you want to delete files and continue running split_uniprot.pl [y]?\n";
		$| = 1;               # force a flush after print
   		$_ = <STDIN>;
		chomp;<commit_msg>changed the user input required to be the uniprot version number rather than long-winded input and output path names.<commit_after>#!/usr/bin/perl -w

#splits the uniprot xml files into separate files based on the ncbi taxon id. Reads the taxons of interest from a 
#centrally stored file. Source directory and output directory are supplied as command line args, expexts source
#files to be uniprot_sprot.xml uniprot_trembl.xml 

use strict;
use warnings;

my($start, $end, $buffer, $trigger) = ("<entry", "</entry>", '', 'type="NCBI Taxonomy"');
my ($filename, $fname_end);
my ($keep, $taxon) = ("false", '0000');
my (@new_contents, @old_contents);
my %taxons;

#the xml declaration and root element for each output file			
my $prolog = '<?xml version="1.0" encoding="UTF-8"?>
<uniprot xmlns="http://uniprot.org/uniprot"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://uniprot.org/uniprot http://www.uniprot.org/support/docs/uniprot.xsd">';
#define the last elements for each output file
my $element_end = '<copyright>
Copyrighted by the UniProt Consortium, see http://www.uniprot.org/terms
Distributed under the Creative Commons Attribution-NoDerivs License
</copyright>
</uniprot>';

#define source and output directories
my $version = $ARGV[0] or die "\nPlease supply the UniProt version you wish to split.
e.g. 9.3\n\n";
my $source_dir = "/shared/data/uniprot/$version/";

my $split_dir = "/shared/data/uniprot/$version/split/";

#create output dir, empty it if already exists?
if(!-e $split_dir ){
	mkdir ("$split_dir", 0755) || die "Cannot mkdir newdir: $!";
}else{
	opendir(DIR,$split_dir) || die("Cannot open directory !\n");
	@old_contents=grep(!/^\.\.?$/,readdir DIR);
	closedir(DIR);
	if(@old_contents){
		print "\n!!$split_dir is not empty!!\nDo you want to delete files and continue running split_uniprot.pl [y]?\n";
		$| = 1;               # force a flush after print
   		$_ = <STDIN>;
		chomp;
{'fraction_non_alphanumeric': 0.14865881173226372, 'fraction_numerical': 0.011782401604412133, 'mean_word_length': 4.503448275862069, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 2, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 14}, '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': '5421293', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1364, 'n_words': 425}