Py script not running properly on Linux/Ubuntu - linux

I have the following files:
SRR15013283_1.fastq SRR15013283_2.fastq SRR15013284_1.fastq SRR15013284_2.fastq
I was trying to run my python script name trimScript_Denovo.py but keeps returning blank, not running.
My script is this
import sys
import os
baseCommand = "java -jar /home/user/sra_data/Trimmomatic-0.39/trimmomatic-0.39.jar PE -phred33"
baseParamter = "ILLUMINACLIP:/home/user/sra_data/Trimmomatic-0.39/adapters/TruSeq3-PE.fa:2:30:10 LEADING:
3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:36"
fileBaseName = "SRR"
extName = ".fastq"
for i in range(1,len(sys.argv)):
accessionName = sys.argv[i]
inputFile1 = fileBaseName + accessionName + "_1" + extName
inputFile2 = fileBaseName + accessionName + "_2" + extName
outputPFile1 = fileBaseName + accessionName + "_1_P" + extName
outputUPFile1 = fileBaseName + accessionName + "_1_UP" + extName
outputPFile2 = fileBaseName + accessionName + "_2_P" + extName
outputUPFile2 = fileBaseName + accessionName + "_2_UP" + extName
fetchCommand = baseCommand + " " + inputFile1 + " " + inputFile2 + " " + outputPFile1 + " " + outputUPF
ile1 + " " + outputPFile2 + " " + outputUPFile2 + " " + baseParamter
os.system(fetchCommand)
to run the script I did python3 trimScript_Denovo.py but keeps returning blank not producing anything.
Any help is appreciated.

Related

How can I debug or catch exceptions when a cgi script executes with just 1 command offlineimap?

How can I debug a cgi script executing just 1 command offlineimap ?
The script uses just input from the user containing source and destination details and executes the offlineimap command. Sometimes if the source has some issues, the migration doesn't happen to the destination mailbox. I need to catch all these exceptions. Is there a way to do it? Main part of the script as follows:
f = open(os.path.join(mfolder_path,mfile),"w+")
f.write(
"[general]\n"
"accounts = " + muserpart + '\n'
"[Account " + muserpart + "]\n"
"localrepository = " + muserpart + "-Local\n"
"remoterepository = " + muserpart + "-Remote\n\n"
"[Repository "+ muserpart + "-Local]\n"
"type = IMAP\n"
"remotehost = " + mremote_host + "\n"
"remoteuser = " + mremote_user + "\n"
"remotepass = " + mremote_pass + "\n"
"ssl = no" + "\n"
"starttls = yes" + "\n"
"#createfolders = no" + "\n\n"
"[Repository "+ muserpart + "-Remote]\n"
"type = IMAP\n"
"remotehost = " + mhost + "\n"
"remoteuser = " + musername + "\n"
"remotepass = " + mpassword + "\n\n"
"ssl = " + mssl + "\n"
+ mstring +
"readonly = yes\n"
'nametrans = lambda f: "Old-" + f\n'
)
f.close()
'''
# py3.5 upwards
process = subprocess.Popen(['offlineimap', '-c', mfile],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
#stdout, stderr = process.communicate()
'''
try:
message = 'Started syncing the mails...'
#py2.7
subprocess.call(['offlineimap', '-c', mfile],
stdout=subprocess.PIPE)
except Exception as e:
print(e)
message = e
n = 0

AWS S3 Authenticating Requests Using Query Parameters to download file with custom name

I'm trying to create a signed URL of a file that can let the user download file from the S3 bucket.
I'm following this way written in docs.
The generated signature is working perfectly and it gets to download the file as well when a user visits the URL. The problem is that I want the name of the downloaded file to be custom.
For example: FileKey: tg6AbybBgFMidmKy5dz4vVXZ FileName: test.xlsx
The file is saved on S3 with the key and without the file extension.
So, when a user downloads the file, it's extensionless and hence unrecognized by OS. I want it to be downloaded with the FileName. I tried adding response-content-disposition in the query but it throws the error:
Below is the code I'm using right now.
# Create a date for headers and the credential string
time = datetime.datetime.utcnow()
amz_date = time.strftime('%Y%m%dT%H%M%SZ')
datestamp = time.strftime('%Y%m%d') # Date w/o time, used in credential scope
# **CREATE A CANONICAL REQUEST**
canonical_uri = '/' + document_key
canonical_headers = 'host:' + bucket_url + '\n'
algorithm = 'AWS4-HMAC-SHA256'
credential_scope = datestamp + '/' + region + '/' + service + '/' + 'aws4_request'
# Create the canonical query string in URL-encoded (space=%20).
canonical_querystring = 'response-content-disposition=attachment; filename="' + document_name + '"; filename*=UTF-8\'\'' + document_name
canonical_querystring += '&response-content-type=' + document_type
canonical_querystring += '&X-Amz-Algorithm=AWS4-HMAC-SHA256'
canonical_querystring += '&X-Amz-Credential=' + quote_plus(access_key + '/' + credential_scope, safe='')
canonical_querystring += '&X-Amz-Date=' + amz_date
canonical_querystring += '&X-Amz-Expires=' + url_expiry
canonical_querystring += '&X-Amz-SignedHeaders=' + signed_headers
canonical_request = request_method + '\n' + canonical_uri + '\n' + canonical_querystring + '\n' + canonical_headers.lower() + '\n' + signed_headers.lower()
# CREATE THE STRING TO SIGN
string_to_sign = algorithm + '\n' + amz_date + '\n' + credential_scope + '\n' + hashlib.sha256(canonical_request.encode('utf-8')).hexdigest()
# CALCULATE THE SIGNATURE
signing_key = getSignatureKey(secret_key, datestamp, region, service)
signature = hmac.new(signing_key, (string_to_sign).encode("utf-8"), hashlib.sha256).hexdigest()
# ADD SIGNING INFORMATION TO THE REQUEST
canonical_querystring += '&X-Amz-Signature=' + signature
# Merge for downloadable URL
download_url = 'https://' + bucket_url + canonical_uri +'?' + canonical_querystring
I'm not using AWS SDK. I'm trying to do it on my own!
EDIT: Even after adding & which was missing, I was getting a signature mismatch.
The issue was with encoding and I missed a & in canonical_querystring = 'X-Amz-Algorithm! It killed my 3 days looking around all forums and trying different things!
Here's the working piece of code!
# Create a date for headers and the credential string
time = datetime.datetime.utcnow()
amz_date = time.strftime('%Y%m%dT%H%M%SZ')
datestamp = time.strftime('%Y%m%d') # Date w/o time, used in credential scope
# **CREATE A CANONICAL REQUEST**
canonical_uri = '/' + document_key
canonical_headers = 'host:' + bucket_url + '\n'
algorithm = 'AWS4-HMAC-SHA256'
credential_scope = datestamp + '/' + region + '/' + service + '/' + 'aws4_request'
# Create the canonical query string in URL-encoded (space=%20).
canonical_querystring = 'X-Amz-Algorithm=AWS4-HMAC-SHA256'
canonical_querystring += '&X-Amz-Credential=' + quote_plus(access_key + '/' + credential_scope, safe='')
canonical_querystring += '&X-Amz-Date=' + amz_date
canonical_querystring += '&X-Amz-Expires=' + url_expiry
canonical_querystring += '&X-Amz-SignedHeaders=' + signed_headers
canonical_querystring += '&response-content-disposition=' + quote('attachment; filename=\"' + document_name + '\"; filename*=UTF-8\'\'' + document_name, safe='')
canonical_querystring += '&response-content-type=' + quote(document_type, safe='')
canonical_request = request_method + '\n' + canonical_uri + '\n' + canonical_querystring + '\n' + canonical_headers.lower() + '\n' + signed_headers.lower() + '\n' + 'UNSIGNED-PAYLOAD'
# CREATE THE STRING TO SIGN
string_to_sign = algorithm + '\n' + amz_date + '\n' + credential_scope + '\n' + hashlib.sha256(canonical_request.encode('utf-8')).hexdigest()
# CALCULATE THE SIGNATURE
signing_key = getSignatureKey(secret_key, datestamp, region, service)
signature = hmac.new(signing_key, (string_to_sign).encode("utf-8"), hashlib.sha256).hexdigest()
# ADD SIGNING INFORMATION TO THE REQUEST
canonical_querystring += '&X-Amz-Signature=' + signature
# Merge for downloadable URL
download_url = 'https://' + bucket_url + canonical_uri +'?' + canonical_querystring
I was using
quote_plus('attachment; filename=\"' + document_name + '\"; filename*=UTF-8\'\'' + document_name,)
instead of which I had to use
quote('attachment; filename=\"' + document_name + '\"; filename*=UTF-8\'\'' + document_name, safe='')
Using this method/logic you can generate link of S3 Object with custom filename without using aws-sdk

TypeError in Python 3 with the print function

So I have been following this code and placed it in and it all seemed to be going well until the last line where I was printing the final string and a TypeError came up. Where is my mistake?
kingName = input("Yo King! Please type in your name at the prompt")
numJewels = input("Hey " + kingName + ", how many jewels are there?")
numJewels = int(numJewels)
costOfEachJewel = input("Yo " + kingName + ", how much does each jewel cost?")
costOfEachJewel = int(costOfEachJewel)
print (costOfEachJewel * numJewels)
dudeNames = ["Athos", "Pothos", "Aramis"]
dudeAges = [55,34, 67]
dudeNames.insert(0, "D'Artagnan")
print (dudeNames)
dudeAges.append(16)
print (dudeAges)
tempVariable = dudeNames.pop(0)
tempVariable
dudeNames.append(tempVariable)
print (dudeNames)
print (dudeAges)
print ("Total number of dudes: " + str(len(dudeNames)))
dudeToKill = input("Yo " + kingName + "please enter the # of the dude to kill")
print ("zapping all history of " + str(len(dudeNames[dudeToKill-1])))
dudeToKill must be an int, convert the input to int before performing dudeToKill - 1 operation.
dudeToKill = int(input("Yo " + kingName + "please enter the # of the dude to kill"))
kingName = input("Yo King! Please type in your name at the prompt")
numJewels = int(input("Hey " + kingName + ", how many jewels are there?"))
costOfEachJewel = int(input("Yo " + kingName + ", how much does each jewel cost?"))
print(costOfEachJewel * numJewels)
dudeNames = ["Athos", "Pothos", "Aramis"]
dudeAges = [55, 34, 67]
dudeNames.insert(0, "D'Artagnan")
print(dudeNames)
dudeAges.append(16)
print(dudeAges)
tempVariable = dudeNames.pop(0)
tempVariable
dudeNames.append(tempVariable)
print(dudeNames)
print(dudeAges)
print("Total number of dudes: " + str(len(dudeNames)))
dudeToKill = int(input("Yo " + kingName + "please enter the # of the dude to kill"))
print("zapping all history of " + str(len(dudeNames[dudeToKill-1])))
hope this will help

Why does my lp file give #number for each variable?

I am using Ilog Cplex with Visual C++ 2015 to solve my problem. Generally, when I export lp file of my problem, the lp file will not contain any #number(such #0, #1, and so on) for variables. It is like this:
\ENCODING=ISO-8859-1
\Problem name: IloCplex
Minimize
obj: Ope(1,1,1) + Ope(1,1,2) + Ope(1,1,3) + Ope(1,1,4) + Ope(1,1,5)
+ Ope(1,1,6) + Ope(1,1,7) + Ope(1,1,8) + Ope(1,1,9) + Ope(1,1,10)
+ Ope(1,1,11) + Ope(1,1,12) + Ope(1,1,13) + Ope(1,1,14) + Ope(1,1,15)
+ Ope(1,1,16) + Ope(1,1,17) + Ope(1,1,18) + Ope(1,1,19) + Ope(1,1,20)
+ Ope(1,1,21) + Ope(1,1,22) + Ope(1,1,23) + Ope(1,1,24) + Ope(1,2,1)
+ Ope(1,2,2) + Ope(1,2,3) + Ope(1,2,4) + Ope(1,2,5) + Ope(1,2,6)
+ Ope(1,2,7) + Ope(1,2,8) + Ope(1,2,9) + Ope(1,2,10) + Ope(1,2,11)
+ Ope(1,2,12) + Ope(1,2,13) + Ope(1,2,14) + Ope(1,2,15) + Ope(1,2,16)
+ Ope(1,2,17) + Ope(1,2,18) + Ope(1,2,19) + Ope(1,2,20) + Ope(1,2,21)
+ Ope(1,2,22) + Ope(1,2,23) + Ope(1,2,24) + Ope(2,1,1) + Ope(2,1,2)
+ Ope(2,1,3) + Ope(2,1,4) + Ope(2,1,5) + Ope(2,1,6) + Ope(2,1,7)
+ Ope(2,1,8) + Ope(2,1,9) + Ope(2,1,10) + Ope(2,1,11) + Ope(2,1,12)
+ Ope(2,1,13) + Ope(2,1,14) + Ope(2,1,15) + Ope(2,1,16) + Ope(2,1,17)
+ Ope(2,1,18) + Ope(2,1,19) + Ope(2,1,20) + Ope(2,1,21) + Ope(2,1,22)
+ Ope(2,1,23) + Ope(2,1,24) + Ope(2,2,1) + Ope(2,2,2) + Ope(2,2,3)
+ Ope(2,2,4) + Ope(2,2,5) + Ope(2,2,6) + Ope(2,2,7) + Ope(2,2,8)
+ Ope(2,2,9) + Ope(2,2,10) + Ope(2,2,11) + Ope(2,2,12) + Ope(2,2,13)
+ Ope(2,2,14) + Ope(2,2,15) + Ope(2,2,16) + Ope(2,2,17) + Ope(2,2,18)
+ Ope(2,2,19) + Ope(2,2,20) + Ope(2,2,21) + Ope(2,2,22) + Ope(2,2,23)
+ Ope(2,2,24)
However, today I add some constraints to my model, the lp file gives #number to each variable. It is like this:
\ENCODING=ISO-8859-1
\Problem name: IloCplex
Minimize
obj: Ope(1,1,1)#0 + Ope(1,1,2)#1 + Ope(1,1,3)#2 + Ope(1,1,4)#3 +
Ope(1,1,5)#4
+ Ope(1,1,6)#5 + Ope(1,1,7)#6 + Ope(1,1,8)#7 + Ope(1,1,9)#8
+ Ope(1,1,10)#9 + Ope(1,1,11)#10 + Ope(1,1,12)#11 + Ope(1,1,13)#12
+ Ope(1,1,14)#13 + Ope(1,1,15)#14 + Ope(1,1,16)#15 + Ope(1,1,17)#16
+ Ope(1,1,18)#17 + Ope(1,1,19)#18 + Ope(1,1,20)#19 + Ope(1,1,21)#20
+ Ope(1,1,22)#21 + Ope(1,1,23)#22 + Ope(1,1,24)#23 + Ope(1,2,1)#24
+ Ope(1,2,2)#25 + Ope(1,2,3)#26 + Ope(1,2,4)#27 + Ope(1,2,5)#28
+ Ope(1,2,6)#29 + Ope(1,2,7)#30 + Ope(1,2,8)#31 + Ope(1,2,9)#32
+ Ope(1,2,10)#33 + Ope(1,2,11)#34 + Ope(1,2,12)#35 + Ope(1,2,13)#36
+ Ope(1,2,14)#37 + Ope(1,2,15)#38 + Ope(1,2,16)#39 + Ope(1,2,17)#40
+ Ope(1,2,18)#41 + Ope(1,2,19)#42 + Ope(1,2,20)#43 + Ope(1,2,21)#44
+ Ope(1,2,22)#45 + Ope(1,2,23)#46 + Ope(1,2,24)#47 + Ope(2,1,1)#48
+ Ope(2,1,2)#49 + Ope(2,1,3)#50 + Ope(2,1,4)#51 + Ope(2,1,5)#52
+ Ope(2,1,6)#53 + Ope(2,1,7)#54 + Ope(2,1,8)#55 + Ope(2,1,9)#56
+ Ope(2,1,10)#57 + Ope(2,1,11)#58 + Ope(2,1,12)#59 + Ope(2,1,13)#60
+ Ope(2,1,14)#61 + Ope(2,1,15)#62 + Ope(2,1,16)#63 + Ope(2,1,17)#64
+ Ope(2,1,18)#65 + Ope(2,1,19)#66 + Ope(2,1,20)#67 + Ope(2,1,21)#68
+ Ope(2,1,22)#69 + Ope(2,1,23)#70 + Ope(2,1,24)#71 + Ope(2,2,1)#72
+ Ope(2,2,2)#73 + Ope(2,2,3)#74 + Ope(2,2,4)#75 + Ope(2,2,5)#76
+ Ope(2,2,6)#77 + Ope(2,2,7)#78 + Ope(2,2,8)#79 + Ope(2,2,9)#80
+ Ope(2,2,10)#81 + Ope(2,2,11)#82 + Ope(2,2,12)#83 + Ope(2,2,13)#84
+ Ope(2,2,14)#85 + Ope(2,2,15)#86 + Ope(2,2,16)#87 + Ope(2,2,17)#88
+ Ope(2,2,18)#89 + Ope(2,2,19)#90 + Ope(2,2,20)#91 + Ope(2,2,21)#92
+ Ope(2,2,22)#93 + Ope(2,2,23)#94 + Ope(2,2,24)#95
I do not want #number to appear in my lp file. What should I do?
The LP file format does not allow arbitrary names for variables and/or constraints. You can find details in the user manual at CPLEX > File formats > LP file format.
If any of your variables or constraints has a name that is not supported in the LP file format then this name has to be changed. To avoid the new name clashing with any existing name, CPLEX appends #number to all names in your model.
One likely/frequent unsupported name is a name that starts in e. Try to avoid such names in case you want to export to LP.

im created a word scrambler and i am having difficulty implementing a block of code that scrambles each word individually

print (' ')
print ('=================================')
print ('Options:')
print ('A.) Hello world ---> olHle dlWro')
print ('B.) Hello world ---> Hlelo Wlord')
while True:
#changes input to lowercase letters
sctype = input('Enter scramble type')
sclower = sctype.lower()
#if 'a' or 'b' not in sctype:
#print ('follow directions')
#input and input related variables
print ('There is a 26 character limit')
text = input(' Type your message or word: ')
length = len(text)
remaining = 26 - length
counter = 1
just a fancy cage for length and remaining
print ('============================')
print ('||Length:', length, 'Remaining:', remaining, '||')
print ('============================')
letter order and loop for option A
dash replaces spaces in original text with dashes
a fills in extra character space with spaces so length = 26
b scrambles a in the order it is given
if sclower == 'a':
print ('Results for option A')
print (' ')
dash = text.replace(" ", "-")
a = dash + ' ' * remaining
b = a[25] + a[0] + a[24] + a[1] + a[23] + a[2] + a[22] + a[3] + a[21] +
a[4] + a[20] + a[5] + a[19] + a[6] + a[18] + a[7] + a[17] + a[8] + a[16] +
a[9] + a[15] + a[10] + a[14] + a[11] + a[13] + a[12]
a = b
scrambles a the amount its original text length is
if a == b:
while counter <= length:
b = a[25] + a[0] + a[24] + a[1] + a[23] + a[2] + a[22] + a[3] +
a[21] + a[4] + a[20] + a[5] + a[19] + a[6] + a[18] + a[7] + a[17] + a[8] +
a[16] + a[9] + a[15] + a[10] + a[14] + a[11] + a[13] + a[12]
a = b
nospaces = b.replace(" ", "") #deletes all spaces made in var a
nodashes = nospaces.replace("-", " ") #changes all dashes to spaces
print (counter, '.)', nodashes)
counter += 1
print (' ')
option b
elif sclower == 'b':
print ('Results for option B')
print (' ')
dash = text.replace(" ", "-")
a = dash + ' ' * remaining
b = a[21] + a[23] + a[20] + a[25] + a[22] + a[24] + a[19] + a[2] + a[18] +
a[0] + a[16] + a[1] + a[17] + a[4] + a[15] + a[3] + a[14] + a[5] + a[13] +
a[7] + a[11] + a[6] + a[10] + a[9] + a[12] + a[18]
a = b
if a == b:
while counter <= length :
b = a[21] + a[23] + a[20] + a[25] + a[22] + a[24] + a[19] + a[2] +
a[18] + a[0] + a[16] + a[1] + a[17] + a[4] + a[15] + a[3] + a[14] + a[5] +
a[13] + a[7] + a[11] + a[6] + a[10] + a[9] + a[12] + a[18]
a = b
nospaces = b.replace(" ", "")
nodashes = nospaces.replace("-", " ")
print (counter, '.)', nodashes)
counter += 1
print (' ')
if input("Repeat the program? (Y/N)").strip().upper() != 'Y':
break
i need to impliment the code below into the code above. this will allow the program to scramble each word within a string individually instead of all at once
counter = 0
text = 'Hello World'
split = str.split(text)
for str in split:
no_name = split[counter]
scramble = c[4] + c[0] + c[3] + c[1] + c[2]
counter += 1
print (scramble, end=" ")
PLEASE NOTE: the variable "text" should allow user input in the final version, above is just an example of the structure

Resources