import os


class ResultSaver:

    """

    class to save the results. Path is dependent on the data_dir, tissuetype and mapped = True or False.
    The output is saved to the temp directory in the data folder if crossmapping is necessary.

    """

    def __init__(self, results, organism, wd,  mapped, is_data_dir, tissue, out):

        print("Save results to File !")
        self.path = ""
        if mapped:
            if is_data_dir:
                self.path = os.path.join(wd + "/temp/" + organism + ".gtf")
            else:
                self.path = os.path.join( wd + "/data/temp/" + organism + ".gtf" )
        elif tissue:
            self.path = os.path.join(out+"/"+organism+"_filtered.gtf")
        else:
            self.path = os.path.join(out+"/"+organism+".gtf")

        with open(self.path, "w") as output_file:
            for line in results:
                output_file.write("\t".join(line)+"\n")