<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_write_subset(self, spec_type):
 """ Get a set of fields used to write the header; either 'record' or 'signal' specification fields. Helper function for `get_write_fields`. Gets the default required fields, the user defined fields, and their dependencies. Parameters spec_type : str The set of specification fields desired. Either 'record' or 'signal'. Returns ------- write_fields : list or dict For record fields, returns a list of all fields needed. For signal fields, it returns a dictionary of all fields needed, with keys = field and value = list of channels that must be present for the field. """

        if spec_type == 'record':
            write_fields = []
            record_specs = RECORD_SPECS.copy()

            # Remove the n_seg requirement for single segment items
            if not hasattr(self, 'n_seg'):
                record_specs.drop('n_seg', inplace=True)

            for field in record_specs.index[-1::-1]:
                # Continue if the field has already been included
                if field in write_fields:
                    continue
                # If the field is required by default or has been
                # defined by the user
                if (record_specs.loc[field, 'write_required']
                        or getattr(self, field) is not None):
                    req_field = field
                    # Add the field and its recursive dependencies
                    while req_field is not None:
                        write_fields.append(req_field)
                        req_field = record_specs.loc[req_field, 'dependency']
            # Add comments if any
            if getattr(self, 'comments') is not None:
                write_fields.append('comments')

        # signal spec field. Need to return a potentially different list for each channel.
        elif spec_type == 'signal':
            # List of lists for each channel
            write_fields = []
            signal_specs = SIGNAL_SPECS.copy()

            for ch in range(self.n_sig):
                # The fields needed for this channel
                write_fields_ch = []
                for field in signal_specs.index[-1::-1]:
                    if field in write_fields_ch:
                        continue

                    item = getattr(self, field)
                    # If the field is required by default or has been defined by the user
                    if signal_specs.loc[field, 'write_required'] or (item is not None and item[ch] is not None):
                        req_field = field
                        # Add the field and its recursive dependencies
                        while req_field is not None:
                            write_fields_ch.append(req_field)
                            req_field = signal_specs.loc[req_field, 'dependency']

                write_fields.append(write_fields_ch)

            # Convert the list of lists to a single dictionary.
            # keys = field and value = list of channels in which the
            # field is required.
            dict_write_fields = {}

            # For fields present in any channel:
            for field in set([i for write_fields_ch in write_fields for i in write_fields_ch]):
                dict_write_fields[field] = []

                for ch in range(self.n_sig):
                    if field in write_fields[ch]:
                        dict_write_fields[field].append(ch)

            write_fields = dict_write_fields

        return write_fields