to_excel error: ValueError: <Worksheet ""> is not in list - export-to-excel

I'm quite stumped here. I'm using pandas version 1.3.5 and am trying to replace an excel tab with new data from a dataframe. Seems extremely simple using the below:
Workbook = load_workbook(file_path + '\\' + file_nm + '.xlsx')
writer = pd.ExcelWriter(file_path + '\\' + file_nm + '.xlsx', mode="a", engine='openpyxl',if_sheet_exists='replace')
writer.book = Workbook
df.to_excel(writer,sheet_name='Positions_auto', index=False)*
However, when trying to replace I'm getting the below error:
ValueError: <Worksheet "Positions_auto"> is not in list
I'm googled far and wide and haven't seen similar issues with to_excel.
Any thoughts? I have no clue why it's not working as the documents say.
I feel like i've tried everything

Related

How to use entrezpy and Biopython Entrez libraries to access ClinVar data from genomic position of variant

[Disclaimer: I have published this question 3 weeks ago in biostars, with no answers yet. I really would like to get some ideas/discussion to find a solution, so I post also here.
biostars post link: https://www.biostars.org/p/447413/]
For one of my projects of my PhD, I would like to access all variants, found in ClinVar db, that are in the same genomic position as the variant in each row of the input GSVar file. The language constraint is Python.
Up to now I have used entrezpy module: entrezpy.esearch.esearcher. Please see more for entrezpy at: https://entrezpy.readthedocs.io/en/master/
From the entrezpy docs I have followed this guide to access UIDs using the genomic position of a variant: https://entrezpy.readthedocs.io/en/master/tutorials/esearch/esearch_uids.html in code:
# first get UIDs for clinvar records of the same position
# credits: credits: https://entrezpy.readthedocs.io/en/master/tutorials/esearch/esearch_uids.html
chr = variants["chr"].split("chr")[1]
start, end = str(variants["start"]), str(variants["end"])
es = entrezpy.esearch.esearcher.Esearcher('esearcher', self.entrez_email)
genomic_pos = chr + "[chr]" + " AND " + start + ":" + end # + "[chrpos37]"
entrez_query = es.inquire(
{'db': 'clinvar',
'term': genomic_pos,
'retmax': 100000,
'retstart': 0,
'rettype': 'uilist'}) # 'usehistory': False
entrez_uids = entrez_query.get_result().uids
Then I have used Entrez from BioPython to get the available ClinVar records:
# process each VariationArchive of each UID
handle = Entrez.efetch(db='clinvar', id=current_entrez_uids, rettype='vcv')
clinvar_records = {}
tree = ET.parse(handle)
root = tree.getroot()
This approach is working. However, I have two main drawbacks:
entrezpy fulls up my log file recording all interaction with Entrez making the log file too big to be read by the hospital collaborator, who is variant curator.
entrezpy function, entrez_query.get_result().uids, will return all UIDs retrieved so far from all the requests (say a request for each variant in GSvar), thus this space inefficient retrieval. That is the entrez_uids list will quickly grow a lot as I process all variants from a GSVar file. The simple solution that I have implenented is to check which UIDs are new from the current request and then keep only those for Entrez.fetch(). However, I still need to keep all seen UIDs, from previous variants in order to be able to know which is the new UIDs. I do this in code by:
# first snippet's first lines go here
entrez_uids = entrez_query.get_result().uids
current_entrez_uids = [uid for uid in entrez_uids if uid not in self.all_entrez_uids_gsvar_file]
self.all_entrez_uids_gsvar_file += current_entrez_uids
Does anyone have suggestion(s) on how to address these two presented drawbacks?

Appcelerator Ti.Blob text property is null

I came across a strange issue while reading files from Ti.Filesystem.applicationDataDirectory. Whenever I want to access the text property of the Ti.Blob returned by Ti.Filesystem.File.read() I get null
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'foo.key');
var contents = f.read();
Ti.API.debug('contents: ' + JSON.stringify(contents));
var text = contents.text;
Ti.API.debug('text: ' + JSON.stringify(text)); // is NULL
The file was created like so
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'foo.key');
f.write(JSON.stringify({foo: 'bar'});
I'm developing on Android by the way with 6.0.1.GA
TL;DR it's the file extension that's causing the problem
When looking at the Ti.Blob more thoroughly I found that it says mimeType : application/gpg-keys. After updating my code above so it uses foo.json as filename everything works as expected.

Texture Packer Command line multiple images

I’m using TexturePacker from the command line and am unable to get it to pack multiple sprites into 1 sheet. It allows me to do 1 sprite so the command is fine.
This is the command I am using.
"TexturePacker --format sparrow --texture-format atf --opt DXT5
--max-width 2048 --max-height 2048 --size-constraints POT --pack-mode Best --enable-rotation --trim-mode Trim --algorithm MaxRects
--multipack --border-padding 5 --shape-padding 5 --reduce-border-artifacts --scale " + sheetInfo.scale + " --data " + imageOutputDirectory + "\" + lanfPrefix + "\" + sheetInfo.name +
".xml " + "--sheet " + imageOutputDirectory + "\" + lanfPrefix + "\"
+ sheetInfo.name + ".atf image1.png image2.png";
Any ideas why this isn't working? According to the documentation, it should work.
I was unable to find any real way to fix this even contacted the developer of texture packer but got no response. Instead I was able to accomplish the desired outcome by copying all needed files to a temp directory and then add the directory to the end of the texturepacker call instead of individual images.
Due to the poor TexturePacker documentation, it took me much trial and error to figure this out!
To add multiple images to a single sprite sheet, here is a sample command that will create an atlas called out.png (the default) containing images img_1 to img_4...
TexturePacker --format unity-texture2d img_1.png img_2.png img_3.png img_4.png
The key is the list of image filenames separated only by spaces. I am working from Python, so here is the script I use to create the same atlas that the sample line above will give you. Using glob with wildcards allows me to select images from a folder containing many images and eliminates the need to isolate the files I want into a folder just for TexturePacker's sake.
import subprocess, glob
TP = r"C:\Program Files\CodeAndWeb\TexturePacker\bin\TexturePacker.exe"
baseFrame = "img"
def FillAtlas(baseFrame):
globString = baseFrame + "_*.png"
frameList = glob.glob(globString)
imgList = []
for frame in frameList:
imgList.append(frame)
TPargs = [TP, "--format", "unity-texture2d"] + imgList
subprocess.call(TPargs)
FillAtlas(baseFrame)

VB 2010 retrieve image

Good day sirs. I'm trying to retrieve a photo from my access database then load it in a PictureBox but I have this kind of problem which I can't resolve.
I have seen questions similar to mine but I can't understand the solutions given by others as I'm just a newbie. Will someone please help me correct my codes for retrieving image file from access database. Thanks
I'm using access database and Visual Basic 2010.
Here's the code:
Dim arrImage() As Byte
Dim myMS As New IO.MemoryStream
Dim da As New OleDb.OleDbDataAdapter("SELECT *
FROM tblEmp
WHERE EmployeeID= '"
& Me.txtID.Text
& "'", con)
Dim dt As New DataTable
da.Fill(dt)
If dt.Rows.Count > 0 Then
If Not IsDBNull(dt.Rows(0).Item("Picture")) Then
arrImage = dt.Rows(0).Item("Picture")
For Each ar As Byte In arrImage
myMS.WriteByte(ar)
Next
'
inFrm.PictureBox1.Image = Image.FromStream(myMS)
End If
End If
I'm getting a "Parameter is not valid" error from the line
inFrm.PictureBox1.Image = Image.FromStream(myMS)
try replacing the line of code with this
inFrm.PictureBox1.PictureData = myMS.Read

Is it practical to call vbscript functions from Ruby using win32ole?

Is it practical to call a VBScript function, such as VBScript's Chr(charcode), from Ruby using win32ole?
Background: While working out how to add some nicely formatted headers to an excel worksheet, I followed my standard operating procedure: record an excel macro and copy and paste the code.
VBScript:
ActiveWindow.View = xlPageLayoutView
With ActiveSheet.PageSetup
' Irrelevant options snipped
.CenterHeader = "&F" & Chr(10) & "&A"
' More irrelevant options snipped
End With
The following Ruby code
# workbook is an existing workbook object
worksheet = workbook.Worksheets.Add
worksheet.PageSetup.CenterHeader = "&F \n &A"
works, but I had to look up the Chr(charcode) documentation to check it was the exact same thing. I tried doing
worksheet.PageSetup.CenterHeader = "&F" + workbook.Chr(10) + "&A"
but got
WIN32OLERuntimeError: unknown property or method: `Chr'
HRESULT error code:0x80020006
Unknown name.
from (irb):6:in `method_missing'
from (irb):6
from c:/Ruby19/bin/irb:12:in `<main>'
Is there any practical way to do the latter approach?
I wouldn't call a vbscript script for something that is easier done in Ruby but it is possible.
How you requested it:
require 'win32ole'
sc = WIN32OLE.new("ScriptControl")
sc.language="VBScript"
center_header = sc.eval('"&F" & Chr(10) & "&A"') #"&F\n&A"
and how you could do it in Ruby itself
"&F" + 10.chr + "&A" #"&F\n&A"
or
"&F\n&A" #"&F\n&A"
EDIT: For 64bit windows that wouldn't work any longer out of the box, you need to install a 64 bit dll that you can find at https://tablacus.github.io/scriptcontrol.html (The site is in japanese so translate the page in your browser)
how 'bout
worksheet.PageSetup.CenterHeader = "&F" + 10.chr + "&A"

Resources