<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">=head1 NAME

Script::RemoveTrack - implemention of bin/remove-track.pl

=head1 DESCRIPTION

Do C&lt;perldoc bin/remove-track.pl&gt; to see usage documentation.

=cut

package Bio::JBrowse::Cmd::RemoveTrack;
use strict;
use warnings;

use File::Path ();
use File::Spec;

use JsonFileStorage;
use base 'Bio::JBrowse::Cmd';

sub option_defaults {
    ( dir =&gt; 'data/' )
}

sub option_definitions {
    (
        shift-&gt;SUPER::option_definitions,
        'dir|out=s',
        'quiet|q',
        'delete|D',
        'trackLabel=s@',
    );
}

sub run {
    my ( $self ) = @_;
    for my $label (@{ $self-&gt;opt('trackLabel') || []}) {
        $self-&gt;delete_track( $label );
    }
}

sub delete_track {
    my ( $self, $trackLabel ) = @_;

    my $deleted_conf;

    # remove the track configuration and print it
    JsonFileStorage-&gt;new( $self-&gt;opt('dir'), 0, { pretty =&gt; 1 })
                   -&gt;modify( 'trackList.json', sub {
                         my ( $json ) = @_;
                         $json or die "The trackList.json file in ".$self-&gt;opt('dir')." could not be read.\n";
                         $json-&gt;{tracks} = [
                             map {
                                 if( $_-&gt;{label} eq $trackLabel ) {
                                     # print the json
                                     $self-&gt;print( "removing track configuration:\n".JSON-&gt;new-&gt;encode( $_ ) );
                                     $deleted_conf = $_;
                                     ()
                                 } else {
                                     $_
                                 }
                             }
                             @{$json-&gt;{tracks} || []}
                         ];
                         return $json;
                     });

    if( ! $deleted_conf ) {
        $self-&gt;print( "No track found with label $trackLabel" );
        return;
    }

    if( $self-&gt;opt('delete') ) {
        # delete the track data
        $self-&gt;print( "Deleting track data for $trackLabel" );
        my @trackdata_paths = (
            File::Spec-&gt;catdir( $self-&gt;opt('dir'), 'tracks', $deleted_conf-&gt;{label} || die ),
        );
        if( !@trackdata_paths ) {
            $self-&gt;print( "Unable to automatically remove track data for $trackLabel (type '$deleted_conf-&gt;{type}').  Please remove it manually." );
        } else {
            $self-&gt;print( "Deleting: @trackdata_paths" );
            File::Path::rmtree( \@trackdata_paths );
        }
    } else {
        $self-&gt;print( "--delete not specified; not deleting data directory for $trackLabel" );
    }
}

sub print {
    my $self = shift;
    print( @_, "\n" ) unless $self-&gt;opt('quiet');
    return;
}

1;
</pre></body></html>