Commit 988a1c2f authored by Adrian Nievergelt's avatar Adrian Nievergelt
Browse files

added MOTL multiplyer scripts for general use

parent 9bca8552
Pigino Lab, MPI-CBG
Edits the csv file, doubling the x,y,z values,
deletes last semicolon from each line, and then replaces
all the semicolons with comma
import fileinput
import sys
import codecs
import os
with fileinput.input(inplace=True) as f:
with fileinput.input(inplace=True) as f1:
#Skips the first line in the csv file
print("CCC,reserved,reserved,pIndex,wedgeWT,NA,NA,NA,NA,NA,xOffset,yOffset,zOffset,NA,NA,reserved,EulerZ(1),EulerZ(3),EulerX(2),reserved,CREATED WITH PEET Version 1.9.1 04/01/2014")
for line in f:
#removes ; from the end of all lines where it appears
#leaves all other lines unchanged
line = line.rstrip('\n');
#if line.endswith(';'):
#line = line[:-1]
#array that stores the index value of all the semicolons in the line
sc_pos_array = [i for i,x in enumerate(line) if x == ',']
#Multiplies and replaces x,y,z values by 2* the value
line = line[0:sc_pos_array[9]+1] + str(2 * float(line[sc_pos_array[9]+1 : sc_pos_array[10]])) + "," + str(2 * float(line[sc_pos_array[10]+1 : sc_pos_array[11]])) + "," + str(2 * float(line[sc_pos_array[11]+1 : sc_pos_array[12]])) + line[sc_pos_array[12]:]
#finally, replace all the semicolons with comma
#line = line.replace(';',',')
# APN - 2019-05-06
import os,sys
import argparse
import matplotlib.pyplot as plt
import csv
parser = argparse.ArgumentParser(description = "Takes a PEET motif list (MOTL) file and duplicates the motif descriptor lines a specified number of times.")
# parser.add_argument("-f", "--file", help="create overlay for a single file",
parser.add_argument('-i', '--input', nargs='?', default='.', help='Input file to process')
parser.add_argument('-o', '--output', nargs='?', default='.', help='Output file to write to. If no argument is provided, a _mult suffix will be added to the original file name')
parser.add_argument('-n', '--number', nargs='?', type=int, default='4', help='How many times to duplicate data lines')
parser.add_argument('-H', '--headerLines', nargs='?', type=int, default='1', help='Number of header lines in file')
parser.add_argument('-it', '--ignoreTail', nargs='?', type=int, default=0, help='Ignores the given number of columns at the end of the file when parsing')
parser.add_argument('-g', '--graph', action='store_true', help='Store a graph of the corrected and uncorrected line intensities for debug purposes.')
args = parser.parse_args()
def row_count(filename):
with open(filename) as in_file:
return sum(1 for _ in in_file)
if args.input == '.':
print("Missing input file");
if args.output == '.':
inPath = os.path.splitext(args.input)
args.output = inPath[0] + "_mult" + inPath[1]
if args.number < 1:
print("Data line duplication argument must be at least 1.")
args.ignoreTail = abs(args.ignoreTail)
with open(args.input, 'r') as csvInFile, open(args.output, 'w') as csvOutFile:
csvReader = csv.reader(csvInFile, delimiter=',', quotechar='#')
csvWriter = csv.writer(csvOutFile, delimiter=',', quotechar='#')
lastLineNumber = row_count(args.input)
for row in csvReader:
if csvReader.line_num <= args.headerLines or csvReader.line_num == lastLineNumber:
# PEET column descriptor line or last line, don't duplicate
if csvReader.line_num <= args.headerLines:
# Data line, write as many times as requested
for i in range(args.number):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment