<commit_before>#!/usr/bin/perl

#use warnings;
use strict;

use PathwayTools::Pathway;
use PathwayTools::PathwayElement;
use PathwayTools;
use SOAP::Lite;
use HashSpeciesList;

#
# Script to convert single target pathway at WikiPathways from a source file.
# User enters WP identifiers for from and to pathways
# Necessary input files: 
# Homology information from Homologene for relevant species conversion
# Homology information from BioMART for relevant species conversion
# Gene symbol information for source and target species from BioMART
# Output:
# Updates (overwrites) target pathway at WP 

#####################

#Define log files
#Tracks IDs that didn't convert and percentage conversion per pathway.
my $outfilename1 = "Log-HomologyConvert-DataNodeConversion.txt";	
unless ( open(LOGFILE1, ">$outfilename1") )
       {
         print "could not open file $outfilename1\n";
         exit;
 	}
print LOGFILE1 "Pathway\tNon-converted IDs\tRedundant Conversions\tPercent converted\n";

####################

my $day = (localtime(time))[3];
my $month = 1+(localtime(time))[4];
my $year = 1900+(localtime(time))[5];
my $date = "$month/$day/$year";
my $cutoff = "20070522222100";
my $maintbot = "MaintBot";
my $fnGPML = "GPML.xsd";

# Use this flag for testing the script on the TEST site
my $testing = "false";

## Under script control
## Usage: ./HomologyConvert-single.pl -t <password> <from WPID> <to WPID> (-t is optional for testing mode)
my $scriptmode = "false";
my $id1 = 0;
my $id2 = 0;
my $password = 0;

if ($#ARGV == 3) { # without testing flag
        $password = $ARGV[0];
        $id1 = $ARGV[1];
        $id2 = $ARGV[2];

        #trigger script mode
        $scriptmode = "true";
} else if ($#ARGV == 4) { # with testing flag
	$testing = "true";
        $password = $ARGV[1];
        $id1 = $ARGV[2];
        $id2 = $ARGV[3];

        #trigger script mode
        $scriptmode = "true";
}

if (!$scriptmode) {
	#Ask user for pathway ID to convert FROM
	print "\nEnter the wikipathways ID of the pathway you want to convert FROM (for example WP56) : ";
	$id1 = <STDIN>;
	chomp ($id1);

	#Ask user for pathway ID to convert TO
	print "\nEnter the wikipathways ID of the pathway you want to convert TO (the pathway will be overwritten) : ";
	$id2 = <STDIN>;
	chomp ($id2);

	#Ask user for WP login password
	print "\nEnter WikiPathways password for user $maintbot: ";
	$password = <STDIN>;
	chomp ($password);
}

# process ids
my $sourceid = ();
my $targetid = ();

if ($id1 =~ /^WP/)<commit_msg>fixed scripting mode logic and encoding<commit_after>#!/usr/bin/perl

#use warnings;
use strict;

use PathwayTools::Pathway;
use PathwayTools::PathwayElement;
use PathwayTools;
use SOAP::Lite;
use HashSpeciesList;

#
# Script to convert single target pathway at WikiPathways from a source file.
# User enters WP identifiers for from and to pathways
# Necessary input files: 
# Homology information from Homologene for relevant species conversion
# Homology information from BioMART for relevant species conversion
# Gene symbol information for source and target species from BioMART
# Output:
# Updates (overwrites) target pathway at WP 

#####################

#Define log files
#Tracks IDs that didn't convert and percentage conversion per pathway.
my $outfilename1 = "Log-HomologyConvert-DataNodeConversion.txt";	
unless ( open(LOGFILE1, ">$outfilename1") )
       {
         print "could not open file $outfilename1\n";
         exit;
 	}
print LOGFILE1 "Pathway\tNon-converted IDs\tRedundant Conversions\tPercent converted\n";

####################

my $day = (localtime(time))[3];
my $month = 1+(localtime(time))[4];
my $year = 1900+(localtime(time))[5];
my $date = "$month/$day/$year";
my $cutoff = "20070522222100";
my $maintbot = "MaintBot";
my $fnGPML = "GPML.xsd";

# Use this flag for testing the script on the TEST site
my $testing = 0;

## Under script control
## Usage: ./HomologyConvert-single.pl -t <password> <from WPID> <to WPID> (-t is optional for testing mode)
my $scriptmode = 0;
my $id1 = 0;
my $id2 = 0;
my $password = 0;

if ($#ARGV == 3) { # with testing flag
        $testing = 1; # true!
        $password = $ARGV[1];
        $id1 = $ARGV[2];
        $id2 = $ARGV[3];

        #trigger script mode
        $scriptmode = 1; # true!
} elsif ($#ARGV == 2) { # without testing flag
        $password = $ARGV[0];
        $id1 = $ARGV[1];
        $id2 = $ARGV[2];

        #trigger script mode
        $scriptmode = 1; #true!
}

if (!$scriptmode) {
	#Ask user for pathway ID to convert FROM
	print "\nEnter the wikipathways ID of the pathway you want to convert FROM (for example WP56) : ";
	$id1 = <STDIN>;
	chomp ($id1);

	#Ask user for pathway ID to convert TO
	print "\nEnter the wikipathways ID of the pathway you want to convert TO (the pathway will be overwritten) : ";
	$id2 = <STDIN>;
	chomp ($id2);

	#Ask user for WP login password
	print "\nEnter WikiPathways password for user $maintbot: ";
	$password = <STDIN>;
	chomp ($password);
}

# process ids
my $sourceid = ();
my $targetid = ();

if ($id1 =~ /^WP/)
{'fraction_non_alphanumeric': 0.13915793635105753, 'fraction_numerical': 0.021150424985174936, 'mean_word_length': 3.769085768143261, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '7374681', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1641, 'n_words': 588}