Example #1
0
    def test_download_file(self):
        url = "http://ndbserver.rutgers.edu/files/ftp/NDB/coordinates/na-chiral-correct/pdb5dg7.ent.gz"
        file = DownloadHelper.download_file(url)
        self.assertIsNotNone(file)

        with self.assertRaises(FileNotFoundError):
            url = "http://ndbserver.rutgers.edu/files/ftp/NDB/coordinates/na-chiral-correct/NotExistingOne.ent.gz"
            DownloadHelper.download_file(url)
Example #2
0
    def test_download_file(self):
        url = "http://ndbserver.rutgers.edu/files/ftp/NDB/coordinates/na-chiral-correct/pdb5dg7.ent.gz"
        file = DownloadHelper.download_file(url)
        self.assertIsNotNone(file)

        with self.assertRaises(FileNotFoundError):
            url = "http://ndbserver.rutgers.edu/files/ftp/NDB/coordinates/na-chiral-correct/NotExistingOne.ent.gz"
            DownloadHelper.download_file(url)
Example #3
0
def parse_search_report(html: str) -> SimpleResult:
    """To parse simple search report from html to SimpleResult

    :param html: html string to parse
    :type html: str
    :return: simple search result
    :rtype: SimpleResult
    """
    result = SearchResult()
    parser = NDBHtmlParser()

    parser.analyze(html)
    count_tag = parser.find_one('span', params={'id': 'numRec'})

    file_tag = parser.find_one('a', after=count_tag, params={'id': 'fileGal'})
    url = file_tag.attrs.get('href', '') if file_tag else ''

    from ndb_adapter.ndb_download import DownloadHelper
    file = DownloadHelper.download_file(NDBBase.siteUrl + url)
    report = parse_xls(file)

    try:
        result.count = int(count_tag.data)
    except (TypeError, ValueError, OverflowError, AttributeError):
        pass

    result.report = report

    return result
Example #4
0
def parse_search_report(html: str) -> SimpleResult:
    """To parse simple search report from html to SimpleResult

    :param html: html string to parse
    :type html: str
    :return: simple search result
    :rtype: SimpleResult
    """
    result = SearchResult()
    parser = NDBHtmlParser()

    parser.analyze(html)
    count_tag = parser.find_one('span', params={'id': 'numRec'})

    file_tag = parser.find_one('a', after=count_tag, params={'id': 'fileGal'})
    url = file_tag.attrs.get('href', '') if file_tag else ''

    from ndb_adapter.ndb_download import DownloadHelper
    file = DownloadHelper.download_file(NDBBase.siteUrl + url)
    report = parse_xls(file)

    try:
        result.count = int(count_tag.data)
    except (TypeError, ValueError, OverflowError, AttributeError):
        pass

    result.report = report

    return result
Example #5
0
    def download(structure_id: str, download_type: DownloadType=DownloadType.Pdb,
                 save: bool=False, target_dir: str='') -> str:
        """Download PDB from NDB

        :param download_type: file download type (default value is DownloadType.PDB)
        :type download_type: DownloadType
        :param target_dir: where to save file (default value is current dir)
        :type target_dir: str
        :param save: tells if file should be saved or not (default value = False)
        :type save: bool
        :param structure_id: structure NDB ID or PDB ID e.g. 4Z6C
        :type structure_id: str
        :return: string or None
        :rtype: str
        """
        return DownloadHelper.download(structure_id, download_type, save, target_dir)
Example #6
0
    def download(self, download_type: DownloadType = DownloadType.Pdb, save: bool = False, target_dir: str = '') -> str:
        """Download PDB from NDB

        :param download_type: file download type (default value is DownloadType.PDB)
        :type download_type: DownloadType
        :param target_dir: where to save file (default value is current dir)
        :type target_dir: str
        :param save: tells if file should be saved or not (default value = False)
        :type save: bool
        :return: string or None
        :rtype: str
        """
        id_structure = self.pdb_id
        if not self.pdb_id:
            print("No pdb_id trying ndb_id")
            id_structure = self.ndb_id

        return DownloadHelper.download(id_structure, download_type, save, target_dir)
Example #7
0
    def download(structure_id: str,
                 download_type: DownloadType = DownloadType.Pdb,
                 save: bool = False,
                 target_dir: str = '') -> str:
        """Download PDB from NDB

        :param download_type: file download type (default value is DownloadType.PDB)
        :type download_type: DownloadType
        :param target_dir: where to save file (default value is current dir)
        :type target_dir: str
        :param save: tells if file should be saved or not (default value = False)
        :type save: bool
        :param structure_id: structure NDB ID or PDB ID e.g. 4Z6C
        :type structure_id: str
        :return: string or None
        :rtype: str
        """
        return DownloadHelper.download(structure_id, download_type, save,
                                       target_dir)
Example #8
0
    def test_download(self):
        pdb_id = "5dg7"
        file = DownloadHelper.download(pdb_id)
        self.assertIsNotNone(file)

        with self.assertRaises(AttributeError):
            DownloadHelper.download("")

        path = getcwd() + sep + "pdb" + pdb_id + ".ent"
        DownloadHelper.download(pdb_id, save=True)
        self.assertTrue(isfile(path))
        remove(path)

        for download_type in filter(lambda w: w is not DownloadType.CifStructureFactors, DownloadType):
                file = DownloadHelper.download("5j0m", download_type)
                self.assertTrue(file)

        file = DownloadHelper.download("5DC3", DownloadType.CifStructureFactors)
        self.assertTrue(file)
Example #9
0
    def test_download(self):
        pdb_id = "5dg7"
        file = DownloadHelper.download(pdb_id)
        self.assertIsNotNone(file)

        with self.assertRaises(AttributeError):
            DownloadHelper.download("")

        path = getcwd() + sep + "pdb" + pdb_id + ".ent"
        DownloadHelper.download(pdb_id, save=True)
        self.assertTrue(isfile(path))
        remove(path)

        for download_type in filter(
                lambda w: w is not DownloadType.CifStructureFactors,
                DownloadType):
            file = DownloadHelper.download("5j0m", download_type)
            self.assertTrue(file)

        file = DownloadHelper.download("5DC3",
                                       DownloadType.CifStructureFactors)
        self.assertTrue(file)