diff dbkit_merge.py @ 3:03e124ff7e26 draft

"planemo upload commit bd03b7888eab0b010acfc3affd38bf4d4e2bb1ef-dirty"
author guerler
date Wed, 16 Dec 2020 13:11:35 +0000
parents 81c7d4668a7e
children
line wrap: on
line diff
--- a/dbkit_merge.py	Wed Dec 16 12:02:48 2020 +0000
+++ b/dbkit_merge.py	Wed Dec 16 13:11:35 2020 +0000
@@ -1,15 +1,15 @@
 #! /usr/bin/env python3
 import argparse
-from os import system
 from os.path import getsize
+from shutil import copyfile
 
-from dbkit_package.DBKit import DBKit
+from dbkit_package.DBKit import DBKit, writeEntry
 
 
 def main(args):
     logFile = open(args.log, "w")
-    outIndex = args.outindex
-    outData = args.outdata
+    outputIndex = args.outputindex
+    outputDatabase = args.outputdatabase
     if getsize(args.firstindex) > getsize(args.secondindex):
         firstIndex = args.firstindex
         firstData = args.firstdata
@@ -20,8 +20,8 @@
         firstData = args.seconddata
         secondIndex = args.firstindex
         secondData = args.firstdata
-    system("cp %s %s" % (firstIndex, outIndex))
-    system("cp %s %s" % (firstData, outData))
+    copyfile(firstIndex, outputIndex)
+    copyfile(firstData, outputDatabase)
     firstEntries = set()
     with open(firstIndex, "r") as f:
         for line in f:
@@ -33,16 +33,13 @@
         for line in f:
             name = line.split()[0]
             secondEntries.append(name)
-    tempFile = "temp.dat"
+    fileName = "temp.dat"
     count = 0
     dbkit = DBKit(secondIndex, secondData)
     for secondKey in secondEntries:
         if secondKey not in firstEntries:
-            dbkit.createFile(secondKey, tempFile)
-            entrySize = getsize(tempFile)
-            currentSize = getsize(outData)
-            system("cat %s >> %s" % (tempFile, outData))
-            system("echo '%s\t%s\t%s' >> %s" % (secondKey, currentSize, entrySize, outIndex))
+            dbkit.createFile(secondKey, fileName)
+            writeEntry(secondKey, fileName, outputIndex, outputDatabase)
             count = count + 1
         else:
             logFile.write("Skipping existing entry %s.\n" % secondKey)
@@ -56,8 +53,8 @@
     parser.add_argument('-fd', '--firstdata', help='First Data file', required=True)
     parser.add_argument('-si', '--secondindex', help='Second Index file', required=True)
     parser.add_argument('-sd', '--seconddata', help='Second Data file', required=True)
-    parser.add_argument('-oi', '--outindex', help='Output Index file', required=True)
-    parser.add_argument('-od', '--outdata', help='Output Data file', required=True)
+    parser.add_argument('-oi', '--outputindex', help='Output Index file', required=True)
+    parser.add_argument('-od', '--outputdatabase', help='Output Data file', required=True)
     parser.add_argument('-log', '--log', help='Log file', required=True)
     args = parser.parse_args()
     main(args)