Exemplo n.º 1
0
    def clean(self):
        file_type = self.cleaned_data.get('file_type', None)
        fastq_type = self.cleaned_data.get('fastq_type')

        # -----------------------------------------
        # If this is a FastQ file, make sure the user
        # has chosen a FastQ type
        # -----------------------------------------
        if file_type == FILE_TYPE_FASTQ and not fastq_type:
            msg = "For FastQ files, please choose a FastQ type"
            self.add_error('fastq_type', msg)
            raise forms.ValidationError(msg)

        # -----------------------------------------
        # Check the dropbox metadata
        # (This should be moved to an async or ajax call in another part of the code )
        # -----------------------------------------
        file_patterns = FilePatternHelper.get_file_patterns_for_dropbox(
            file_type)

        # Use the dropbox API to look at the files under this dropbox_url
        #
        (success, dbox_retriever_obj_or_err_msg) = get_dropbox_metadata_from_link(\
                                self.cleaned_data.get('dropbox_url'),\
                                file_patterns=file_patterns)
        if success:
            self.dropbox_retriever_object = dbox_retriever_obj_or_err_msg
            #self.dropbox_metadata_info = dbox_retriever_obj_or_err_msg.matching_files_metadata

        else:
            #self.add_error('dropbox_url', dbox_metadata_or_err_msg)
            raise forms.ValidationError(dbox_metadata_or_err_msg)

        return self.cleaned_data
Exemplo n.º 2
0
    def clean(self):
        file_type = self.cleaned_data.get('file_type', None)
        fastq_type = self.cleaned_data.get('fastq_type')

        # -----------------------------------------
        # If this is a FastQ file, make sure the user
        # has chosen a FastQ type
        # -----------------------------------------
        if file_type == FILE_TYPE_FASTQ and not fastq_type:
            msg = "For FastQ files, please choose a FastQ type"
            self.add_error('fastq_type', msg)
            raise forms.ValidationError(msg)

        # -----------------------------------------
        # Check the dropbox metadata
        # (This should be moved to an async or ajax call in another part of the code )
        # -----------------------------------------
        file_patterns = FilePatternHelper.get_file_patterns_for_dropbox(file_type)

        # Use the dropbox API to look at the files under this dropbox_url
        #
        (success, dbox_retriever_obj_or_err_msg) = get_dropbox_metadata_from_link(\
                                self.cleaned_data.get('dropbox_url'),\
                                file_patterns=file_patterns)
        if success:
            self.dropbox_retriever_object = dbox_retriever_obj_or_err_msg
            #self.dropbox_metadata_info = dbox_retriever_obj_or_err_msg.matching_files_metadata

        else:
            #self.add_error('dropbox_url', dbox_metadata_or_err_msg)
            raise forms.ValidationError(dbox_metadata_or_err_msg)

        return self.cleaned_data
Exemplo n.º 3
0
    def step2_check_file_matches(self):
        """
        Does the dropbox metadata contain files that we're looking for?
        """
        if self.err_found:
            return False
        assert isinstance(self.dropbox_link_metadata, dict),\
            "Do not call this unless step 1, retrieval of Dropbox metadata is successful"
        assert "is_dir" in self.dropbox_link_metadata,\
            "Do not call this unless step 1, retrieval of Dropbox metadata is successful.\
             (Metadata doesn't look good. Missing key 'is_dir')"

        # -------------------------------------
        # Handle a Dropbox link to a file?
        # -------------------------------------
        if self.dropbox_link_metadata['is_dir'] is False:  # Yes, this is a file
            self.is_directory_link = False

            # Does it match?
            fpath = self.dropbox_link_metadata['path']
            if self.does_file_match_criteria(fpath):
                self.matching_files_metadata.append(fpath)
                return True
            else:
                file_msg = FilePatternHelper.get_file_patterns_err_msg(
                    self.file_patterns)

                self.add_err_msg('No files match what we are looking for. %s' %
                                 file_msg)
                return False

        # -------------------------------------
        # Handle a Dropbox link to a directory?
        # -------------------------------------
        self.is_directory_link = True

        # This is a directory, check each file
        #
        if not 'contents' in self.dropbox_link_metadata:
            self.add_err_msg("The directory is empty.  No 'contents' key")
            return False

        # Iterate through files
        #
        for file_info in self.dropbox_link_metadata['contents']:
            if file_info[
                    'is_dir'] is True:  # This is a subdirectory, keep going
                continue
            fpath = file_info['path']  # Assume the 'path' is always here
            if self.does_file_match_criteria(fpath):
                self.matching_files_metadata.append(fpath)

        if len(self.matching_files_metadata) == 0:
            self.add_err_msg('No files match what we are looking for. \
            Please make sure you have at least one ".fastq" or ".vcf" file.')
            return False

        # We've got something
        return True
Exemplo n.º 4
0
    def step2_check_file_matches(self):
        """
        Does the dropbox metadata contain files that we're looking for?
        """
        if self.err_found:
            return False
        assert isinstance(self.dropbox_link_metadata, dict),\
            "Do not call this unless step 1, retrieval of Dropbox metadata is successful"
        assert "is_dir" in self.dropbox_link_metadata,\
            "Do not call this unless step 1, retrieval of Dropbox metadata is successful.\
             (Metadata doesn't look good. Missing key 'is_dir')"

        # -------------------------------------
        # Handle a Dropbox link to a file?
        # -------------------------------------
        if self.dropbox_link_metadata['is_dir'] is False:   # Yes, this is a file
            self.is_directory_link = False

            # Does it match?
            fpath = self.dropbox_link_metadata['path']
            if self.does_file_match_criteria(fpath):
                self.matching_files_metadata.append(fpath)
                return True
            else:
                file_msg = FilePatternHelper.get_file_patterns_err_msg(self.file_patterns)

                self.add_err_msg('No files match what we are looking for. %s' % file_msg)
                return False

        # -------------------------------------
        # Handle a Dropbox link to a directory?
        # -------------------------------------
        self.is_directory_link = True

        # This is a directory, check each file
        #
        if not 'contents' in self.dropbox_link_metadata:
            self.add_err_msg("The directory is empty.  No 'contents' key")
            return False

        # Iterate through files
        #
        for file_info in self.dropbox_link_metadata['contents']:
            if file_info['is_dir'] is True: # This is a subdirectory, keep going
                continue
            fpath = file_info['path']   # Assume the 'path' is always here
            if self.does_file_match_criteria(fpath):
                self.matching_files_metadata.append(fpath)

        if len(self.matching_files_metadata) == 0:
            self.add_err_msg('No files match what we are looking for. \
            Please make sure you have at least one ".fastq" or ".vcf" file.')
            return False

        # We've got something
        return True
Exemplo n.º 5
0
 def get_fastq_extension_type(self):
     """
     For pair-ended FastQ files, figure out the extension
     """
     return FilePatternHelper.get_fastq_extension_type(self.selected_files)