/
mysql_queryfetch.py
43 lines (37 loc) · 1.45 KB
/
mysql_queryfetch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys, getopt
from pymysql import connect, err, sys, cursors
import pandas as pd
from sqlfun_class import SQLfunc
def main(argv):
inputfile = ''
outputfile = ''
# try:
# opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
# except getopt.GetoptError:
# print ("test.py -i <inputfile> -o <outputfile>")
# sys.exit(2)
# for opt, arg in opts:
# if opt == '-h':
# print ("test.py -i <inputfile> -o <outputfile>")
# sys.exit()
# elif opt in ("-i", "--ifile"):
# inputfile = arg
# elif opt in ("-o", "--ofile"):
# outputfile = arg
try:
opts, args = getopt.getopt(argv,"ho:",["ofile="])
except getopt.GetoptError:
print ("test.py -o <onputfile>")
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print ("test.py -o <onputfile>")
sys.exit()
elif opt in ("-o", "--ofile"):
outputfile = arg
# sql = 'CREATE DATABASE IF NOT EXISTS rpoB_reads_assignment'
# cursor.execute(sql)
#sql = 'SELECT reads_name, sequence FROM reads_trimmed_merged.DS2_1_trimmed_merged_fa WHERE id < 100 AND SUBSTRING(reads_name, 2) NOT IN (SELECT reads_name from reads_assignment.DS2_1_assignment);'
sqlfun = SQLfunc()
sqlfun.fetch_seq_exclude("xchen_projects", "SS37_trimmed_fa", "blastn_SS37_reads_taxa_tmp", outputfile)
if __name__ == "__main__": main(sys.argv[1:])