Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
master_project_JLU2018/bin/3.1_create_gtf/Modules/Validator.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
47 lines (32 sloc)
1.27 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
class Validator: | |
""" | |
Class to validate and sort the gtf-output-file. | |
@author: Sebastian Beyvers | |
@contact: sebastian.beyvers@med.uni-giessen.de | |
""" | |
def __init__(self, out_file): | |
# Constructor | |
# input_parameter: out_file = path to output file | |
self.out_file = out_file | |
self.sort_file() | |
self.test_read_file() | |
def sort_file(self): | |
# function that utilizes linux sort to sort the output by chromosome and start coordinate, | |
# this improves handling in tools like IGV | |
command = "sort -V -k1,1 -k4,4n -o "+self.out_file+" "+self.out_file | |
os.system(command) | |
def test_read_file(self): | |
# Method to test the output file-format | |
with open(self.out_file) as outfile: | |
line = outfile.readline() | |
if line: | |
if len(line.split("\t")) == 9: | |
print("Validation complete no errors found !") | |
else: | |
print("Incorrect output Format: Try again after deleting data folder.") | |
else: | |
print("Outputfile not in correct Format: Try again after deleting data Folder.") | |
exit(1) | |
# Debug | |
# v = Validator("/home/basti/Schreibtisch/test_hg38.gtf") |