Save#

A simple example on how Variant can save the output.

[1] - 
from os import getcwd
from os.path import dirname
from openvariant import Annotation, Variant

dataset_file = f'{dirname(getcwd())}/datasets/sample1/22f5b2f.wxs.maf.gz'
annotation_file = f'{dirname(getcwd())}/datasets/sample1/annotation_maf.yaml'

Annotation object generated from annotation file. Parameters:

  • annotation_path - Path of annotation file.

Variant object to iterate through the parsed file. Parameters:

  • path - Path of input file.

  • annotation - Annotation object which input will be parsed.

  • skip_files - Skip unreadable files and directories.

One of the main functions of Variant is read. It will generate an iterator to scan the parsed file.

save function parameters:

  • file_path - Path where file will be saved.

  • mode - Mode to write the output.

    • a - The cursor starts at the end of the file.

    • w - The cursor starts at the begging of the file.

  • display_header - It will write the headers on the output file.

In this example, it will save the parsed input in an output file.

[2] - 
annotation = Annotation(annotation_file)
result = Variant(dataset_file, annotation)

output_file = f'{dirname(getcwd())}/datasets/sample1/output.tsv'
result.save(file_path=output_file, display_header=True)

It is also possible to combine save function with findfiles which will find any file and then save the parsed output appending it in a single file.

[3] - 
from openvariant import findfiles

output_file_append = f'{dirname(getcwd())}/datasets/sample1/output_append.tsv'

annotation_file = f'{dirname(getcwd())}/datasets/sample1/annotation_maf.yaml'
annotation = Annotation(annotation_file)

dataset_folder = f'{dirname(getcwd())}/datasets/sample1'

for file_path, _ in findfiles(dataset_folder):
    result = Variant(file_path, annotation)

    try:
        result.save(output_file_append, mode="a")
    except NameError:
        pass