#!/usr/bin/env python3

import csv
import os.path
from argparse import ArgumentParser

from fix_chromosome_id import fix_chromosome_id

__author__ = 'groverj3'

# Function to determine if you've passed a valid filename


def file_validity(parser, arg):
    if not os.path.exists(arg):
        parser.error('%s is not a valid file path.' % arg)
    else:
        pass

# Parse command line file path, store in variable

parser = ArgumentParser(description='CoGe-ifier for PileOMeth converts context-specific methylation bedGraph files '
                                    'generated by PileOMeth\'s --methylKit option, or any methylKit compatible file, '
                                    'into .csv format for compatibility with CoGe\'s LoadExperiment Functionality.')

parser.add_argument('input_file',
                    help='Input PileOMeth context-specific methylation summary',
                    metavar='File')

parser.add_argument('-c', '--coverage',
                    type=int,
                    help='Minimum coverage to report in an additional output .csv. Default = 1 (Unfiltered)')

parser.add_argument('-u', '--unfiltered',
                    default='t',
                    choices=['t', 'f'],
                    help='Outputs an unfiltered .csv. Default = t')

min_coverage = parser.parse_args().coverage
unfiltered = parser.parse_args().unfiltered
methyl_path = parser.parse_args().input_file

# Check validity of input/output path

file_validity(parser, methyl_path)

# Save paths for later use

coge_filtered_path = '%s.filtered.coge.csv' % methyl_path
coge_unfiltered_path = '%s.coge.csv' % methyl_path

# Let the user know it's working

print('Formatting PileOMeth bedGraph files for CoGe-import from:\n',
      methyl_path)
if min_coverage:
    print('Saving CoGe-formatted and coverage-filtered file to:\n',
          coge_filtered_path)
if unfiltered == 't':
    print('Saving CoGe-formatted unfiltered file to:\n',
          coge_unfiltered_path)

# Open the PileOMeth output file and create an output for CoGe upload

methylKit_formatted = open(methyl_path, 'r')
methylation_summary = csv.reader(methylKit_formatted, delimiter='\t')

if min_coverage:
    coge_filtered_csv = open(coge_filtered_path, 'w')
    coge_formatted_filtered = csv.writer(coge_filtered_csv)
if unfiltered == 't':
    coge_unfiltered_csv = open(coge_unfiltered_path, 'w')
    coge_formatted_unfiltered = csv.writer(coge_unfiltered_csv)

# Write to output files depending on coverage filtered or not

next(methylation_summary)  # Skip header

for row in methylation_summary:
    chrm = fix_chromosome_id(row[1])
    pos = row[2] - 1
    strand = row[3]
    if strand == 'F':
        strand = '1'
    elif strand == 'R':
        strand = '-1'
    coverage = int(row[4])
    dec_met = row[5]
    if min_coverage and coverage >= min_coverage:
        coge_formatted_filtered.writerow(
                [chrm, pos, pos, strand, dec_met, coverage])  # Output as filtered .csv file
    if unfiltered == 't':
        coge_formatted_unfiltered.writerow(
                [chrm, pos, pos, strand, dec_met, coverage])  # Output as unfiltered .csv file

print('\nDone!')

@@ -2630,14 +2630,19 @@
 s = 
+int(
 row%5B2%5D
+)
  - 1

Fix syntax error