biopython FeatureLocation comparison - biopython

I am using biopython to complete a simple task: from a specific genebank fill, extract a gene ID and related information into a table.
When I was trying to compare if the Seq.SeqFeature.SeqFeature.location from different SeqFeature, it gives me False every time. Even in the situation below:
from Bio.SeqFeature import FeatureLocation
location1 = FeatureLocation(0,0,strand = 1)
location2 = FeatureLocation(0,0,strand = 1)
print(location1 == location2) # will print False
Only this will give me a desired result:
print(location1.start == location2.start and location1.end == location2.end and location1.strand == location2.strand) # will print True.
The problem was solved like this, but I am still wandering whether this is by design for some reason or the comparison method just haven't been built in yet.
Below are the process of why I come to this problem:
First I only extracted feat.type == 'CDS' information from genbank file, and found
all pseudo genes are lost.
Then I came up with the idea by recording the information in
feat.type == 'gene' and then look for either 'CDS' or
'misc_feature' to record more information for this gene.
This creates the need of confirming the 'CDS' or 'misc_feature'
is annotated at the same location in case there is multiple
'misc_feature' annotating some domains of the same gene.

I am still wandering whether this is by design for some reason or the
comparison method just haven't been built in yet.
The answer appears to be the latter. As far as I can tell, an __eq__ method for FeatureLocation was supposed to be added in 2011 but didn't make it in. Even other Biopython objects note the lack of ability to compare FeatureLocation objects in their source code comments.
However, it's in the source code for the in progress, not yet released Biopython 1.70
The only difference between the upcoming implementation and yours is comparison of the ref and ref_db fields which default to None, so if you're not using them, no problem.
For more background information, see pull request 1309.

Related

Confused about Google Ads documentation

I've adapted the code at https://developers.google.com/google-ads/api/docs/keyword-planning/generate-keyword-ideas. I don't understand why at one point why the example says,
var response = keywordPlanIdeaService.GenerateKeywordIdeas(request);
and then about three lines later says,
KeywordPlanHistoricalMetrics metrics = result.KeywordIdeaMetrics;
It seems on the one hand to be generating keyword ideas and then on the other giving history.
Now in the KeywordPlanIdeaService documentation it says that there's GenerateKeywordHistoricalMetrics and GenerateKeywordIdeas. However when I try to use the former instead of the latter in the example, VS2022 indicates that the name is unknown.
So my questions are:
What does the C# code on the "idea generation" page demonstrate? Is it demonstrating Ideas or Historical Metrics.
Are these the same, conceptually, as AdWords' IDEAS and STATS respectively?
If it is in fact demonstrating Ideas, how would one adapt it for Historical Metrics?

Swift: Is there an OS call in macOS/iOS similar to NSSpellCheck but for getting a word definition from the dictionary,

I can spell check words like this:
import Cocoa
let words = ["happy","flingey","bookinto"]
let spellCheck = NSSpellChecker()
for word in words {
if spellCheck.checkSpelling(of: word, startingAt: 0).length == 0 {
print("Word: \(word) is good")
} else {
print("Word: \(word) is bad")
}
}
However, the output is:
Word: happy is good
Word: flingey is bad
Word: bookinto is good
There are some (only some) combinations of valid words, like "book into" but with a missing space which the spellchecker still accepts as valid.
I suspect I might be able to tweak how NSSpellChecker operates to eliminate the issue, however, if I can get the next part working, I won't need to worry about this one.
For a later part of the App (a quiz) I want to let the user see a definition of the word within the App. Something like this
import Cocoa
let definer = NSDictionaryDefinition()
let word = "Happy"
if let meaning = definer.getDefinition(for: word) {
print("\(word): \(meaning.getText())")
}
Which would then give:
Happy: feeling or showing pleasure or contentment
NSDictionaryDefinition is just something I made up as the kind of API name I was expecting to find, and obviously given how macOS APIs work it won't be as easy as that, it will probably be within a collection within a container within a callback, or whatever, but I'm happy dealing with all that when I get there, my problem is I can't find any system API that remotely resembles something like NSDictionaryDefinition.
My web search is hampered by the fact that Dictionary is also a Swift Collection Type, so I get hundreds of false hits, but even trawling through many of those, I didn't get lucky.
So next I started looking in the API references on the Apple developer site, which is just as painful because it's so vast and sprawling with little by way of a route map through it, but even then I couldn't locate anything.
Does anyone know if this system API exist for Swift (or even Objective-C). I've always assumed it did because the dictionary comes as standard in macOS and most things in macOS are programable via an API. It needs to be a system native API to work offline and also localise to the user automatically.
Please don't suggest third party resources, as I notice a previous question about that got marked as off-topic here. I'm assuming this question is on topic but I genuinely struggle to gauge it.
Thanks.
Something like this exists on iOS. Look into UIReferenceLibraryViewController. It doesn't give you back the definitions as strings, but you can check if there is a definition for a word and you can show the system-provided dictionary view.

Compare two fields with OGC filter in OL3 and GeoServer

I'm using Opeonlayers 3.18 + GeoServer. I can make a ogc filter for comparing a field and a value. How can i compare two fields?
Code below shows what i'm looking for:
var f = ol.format.ogc.filter.greaterThan('Field1', 100); // this works nicely
var f = ol.format.ogc.filter.greaterThan('Field1', 'Field2'); // this doesn't work
Equivalent working CQL filter is: 'Field1 > Field2'
Regards
This sort of filtering should work. I'd note that many databases may not have a way to perform that filter in an optimal way, and as such, there's a chance that the handling for such a filter is not correct.
The first thing to check out is if the GeoServer logs have any additional information. For most requests, there are log messages which will provide all the details (including the filter) for the request.
If OL3 is making a non-sense request, there should be some kind of parse error first. If the datastore is having trouble with the request, you might see an exception.
To help further, which version of GeoServer and which datastore are you using? Also, is there additional information in the logs?
Update: Based on the comment below, I checked out the Open Layers 3 source. If you look here, it looks like OL3 is treating the first argument as a properyName and the second as a literal. It is probably worth filling a bug/feature request on the project's GitHub page.

CAB file API clarification

Since I'm not really seeing any content anywhere that doesn't point back to the original Microsoft documents on this matter, or source code that really doesn't seem to answer the questions I'm having, I thought I might ask a few things here. (Delphi tag is there because that's what my dev environment is on the code I'm making from this)
That said, I had a few questions the API document wasn't answering. First one: fdi_notify messages. What is "my responsibility" is in coding these: fdintCABINET_INFO: fdintPARTIAL_FILE: fdintNEXT_CABINET: fdintENUMERATE: ? I'll illustrate what I mean by an example. For fdintCLOSE_FILE_INFO, "my responsibility" is to Close a file related to handle given me, and set the file's date and time according to the data passed in fdi_notify.
I figure I'm missing something since my code isn't handling extracting spanned CAB files...any thoughts on how to do this?
What you're more than likely running into is that FDICopy only reads the cab you passed in. It will use fdintNEXT_CABINET to get spanned data for any files you extract in response to fdintCOPY_FILE, but it only calls fdintCOPY_FILE for files that start on that first cab.
To get a directory listing for the entire set, you need to call FDICopy in a loop. Every time you get a fdintCABINET_INFO event, save off the psz1 parameter (next cab name). When FDICopy returns, check that. If it's an empty string you're done, if not call FDICopy again with the next cab as the new path.
fdintCABINET_INFO: The only responsibility for this is returning 0 to continue processing. You can use the information provided (the path of the next cabinet, next disk, path name, nad set ID), but you don't need to.
fdintPARTIAL_FILE: Depending on how you're processing your cabs, you can probably ignore this. You'll only see it for the second and later images in a set, and it's to tell you that the particular entry is continued from a previous cab. If you started at the first cab in the set you'll have already seen an fdintCOPY_FILE for the file. If you're processing random .cabs, you won't really be able to use it either, since you won't have the start of the file to extract.
fdintNEXT_CABINET: You can use this to prompt the user for a new directory for the next cabinet, but for simple spanning support just return 0 if the passed in filename is valid or -1 if it isn't. If you return 0 and the cab isn't valid, or is the wrong one, this will get called again. The easiest approach (if you don't request a new disk/directory), is just to check pfdin^.fdie. If it's FDIError_None it's equal the first time being called for the requested cab, so you can return 0. If it's anything else it's already tried to open the requested cab at least once, so you can return -1 as an error.
fdintENUMERATE: I think you can ignore this. It isn't covered in the documentation, and the two cab libraries I've looked at don't use it. It may be a leftover from a previous API version.

How to create a changelog?

I'm building a site that shows changes in deals that we have in our db. For example, if a deals status changes from pending to win, I want to show it, and if the value goes up or down, I want to show it, that kind of thing. Also, if you open the overview page, I want it to show the history of changes. So I need some kind of change logging, to be able to look in the past. How do I do this?
It is a rails project, but I think that's irrelevant.
I doubt there is any generic solution to this problem.
You can roll out your own. Start by considering all objects that need change logging. How many types are there? How often do you expect changes to occur? This will help you estimate the potential number of changes throughput you'll need to be dealing with. If there aren't too many, just stick them into database. If you are generating a lot, try storing to comma-separated-value file.
I have implemented a similar system before. I had 3 types of changes: 1) property value change, 2) adding of a value to a list, 3) removing value from a list.
I used the following format, stored in a log file:
//For type 1)
1,2011/01/01 00:00:00,MyObject,myProperty,oldValue,newValue
//For type 2)
2,2011/01/01 00:00:00,MyObject,myListProperty,addedValue
//For type 3)
3,2011/01/01 00:00:00,MyObject,myListProperty,removedValue
This captured most information I needed. The value parts were just some user-readable summary of the changed/added/removed property value.
Paper Trail Gem
Since you're on Rails, take a look at the PaperTrail gem. It does exactly what you're looking for and is beautifully built. You'll just need to add in a callback so that your overview page knows that a change occurred. But for the history of a model, just use the built-in PaperTrail functionality.

Resources