How to use the pygtftk.utils.close_properly function in pygtftk

To help you get started, we’ve selected a few pygtftk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dputhier / pygtftk / pygtftk / plugins / intergenic.py View on Github external
message("Searching for intergenic regions.")

    gtf = GTF(inputfile)

    intergenic_regions = gtf.get_intergenic(chrom_info)

    nb_intergenic_region = 1

    for i in intergenic_regions:
        i.name = "region_" + str(nb_intergenic_region)
        write_properly(chomp(str(i)), outputfile)
        nb_intergenic_region += 1

    gc.disable()
    close_properly(outputfile, inputfile)
github dputhier / pygtftk / pygtftk / plugins / join_multi_file.py View on Github external
else:
        target_feature = ",".join(feat_list)

    # -----------------------------------------------------------
    #  Do it
    # -----------------------------------------------------------

    for join_file in matrix_files:
        gtf = gtf.add_attr_from_matrix_file(feat=target_feature,
                                            key=key_to_join,
                                            inputfile=join_file.name)
    gtf.write(outputfile,
              gc_off=True)

    gc.disable()
    close_properly(outputfile, inputfile)
github dputhier / pygtftk / pygtftk / plugins / convergent.py View on Github external
if len(tx_to_convergent_nm):
        gtf = gtf.add_attr_from_dict(feat="transcript",
                                     key="transcript_id",
                                     a_dict=tx_to_convergent_nm,
                                     new_key="convergent")

        gtf = gtf.add_attr_from_dict(feat="transcript",
                                     key="transcript_id",
                                     a_dict=dist_to_convergent,
                                     new_key="dist_to_convergent")

    gtf.write(outputfile,
              gc_off=True)

    close_properly(outputfile, inputfile)
github dputhier / pygtftk / pygtftk / plugins / tss_numbering.py View on Github external
for tx_id in tx_list:
                dist_to_first = abs(int(tss[tx_first]) - int(tss[tx_id]))
                tss_dist_file.write(tx_id + "\t" + str(dist_to_first) + "\n")

        tss_dist_file.close()

        gtf = gtf.add_attr_from_file(feat='transcript',
                                     key='transcript_id',
                                     new_key=key_name_dist,
                                     inputfile=open(tss_dist_file.name),
                                     has_header=False)

    gtf.write(outputfile,
              gc_off=True)

    close_properly(outputfile, inputfile)
github dputhier / pygtftk / pygtftk / plugins / get_feature_list.py View on Github external
def get_feature_list(
        inputfile=None,
        outputfile=None,
        separator=""):
    """
    Get the list of features enclosed in the GTF.
    """

    gtf = GTF(inputfile, check_ensembl_format=False)
    for i in gtf.get_feature_list(nr=True):
        outputfile.write(str(i) + separator)

    gc.disable()
    close_properly(outputfile, inputfile)
github dputhier / pygtftk / pygtftk / plugins / get_example.py View on Github external
message("No corresponding file found", type='ERROR')

            file_path = [x for x in file_path if "__" not in x]
            target_path = os.path.join(pygtftk.__path__[0], 'data', dataset)
            message("Copying from :" + target_path)

            for i in file_path:
                if not os.path.exists(os.path.join(os.getcwd(), os.path.basename(i))):
                    if not quiet:
                        message("Copying file : " + os.path.basename(i), force=True)
                    shutil.copy(i, ".")
                else:
                    if not quiet:
                        message("Copy canceled, file already exist:" + os.path.basename(i), force=True)

    close_properly(outputfile)
github dputhier / pygtftk / pygtftk / plugins / random_list.py View on Github external
type="WARNING")
        number = len(id_list)

    if seed_value is not None:
        random.seed(seed_value, version=1)

    id_list = random.sample(id_list, number)

    message("Printing.")

    my_id = ft_type + "_id"

    gtf.select_by_key(my_id, ",".join(id_list)).write(outputfile,
                                                      gc_off=True)

    close_properly(outputfile, inputfile)
github dputhier / pygtftk / pygtftk / plugins / closest_gn_to_feat.py View on Github external
for gn in closest_cp:
                col_right = ",".join(closest_cp[gn]) + "\t" + ",".join(closest_dist_cp[gn])
                outputfile.write("\t".join(gn) + "\t" + col_right + "\n")
        else:

            # -------------------------------------------------------------------------
            # for each gene print a peak and a dist
            # -------------------------------------------------------------------------

            for gene in closest_cp:

                for peak, dist in zip(closest_cp[gene], closest_dist_cp[gene]):
                    col_right = "\t".join([peak, str(dist)])
                    outputfile.write("\t".join(gene) + "\t" + col_right + "\n")

    close_properly(outputfile, inputfile)