Programming thread -

Meat Poultry Veg

The staff of life
kiwifarms.net
Thread re-railment time!

In my class we are learning Python (v.3 to be exact) as well as using dictionaries. Unfortunately the assigned reading and lecture material do not cover what is needed for the homework (which again makes me question the wisdom of paying $4.6k for material I could have learned for free, besides earning points for a useless MS).

In bioinformatics, there is a file type called FASTA which has the following format:

Code:
>some bullshit here
MAARTHCSWERPLMKDE

>some more bullshit here
MTSWEDFHGIPEEDVMQ

>some more more bullshit here
MKRTYQVPLYIGEQASMNDE

...
...
...

>header
(Sequence of amino acids or nucleic acids)
I need to write a program that counts every instance of NON-HEADER letters such that the output looks like this:

Code:
M: 4533
Q: 5654
V: 3229
etc.
(Obviously these numbers are random, do not correspond to the examples I showed above).

I think that the solution starts with an empty dictionary and involves looping through the file, adding each letter as a key and using the number of occurrences as a value. To skip the headers, the code is

Code:
If line.startswith('>'):
     continue
 
Last edited:

Least Concern

Pretend I have a waifu avatar like everyone else
kiwifarms.net
Okay, and which part are you struggling with? Reading the file? Populating the dictionary? Printing the output?

Or do you just want us to do do your homework for you? Questions like that tend not to go over well on programming-related forums.
 
  • Like
Reactions: 3119967d0c

Degenerated

Artesté
kiwifarms.net
I'm starting to get really burned out in regards to coding. I have the ability to make whatever I want but usually once I start making good progress or overcome some major challenge I lose interest and start working on something new. ?
 
  • Like
Reactions: Ratko_Falco

Meat Poultry Veg

The staff of life
kiwifarms.net
Okay, and which part are you struggling with? Reading the file? Populating the dictionary? Printing the output?

Or do you just want us to do do your homework for you? Questions like that tend not to go over well on programming-related forums.
Fair enough, I did tinker with my own code. Here's what I have so far.

Recap: I am counting all occurrences of an amino acid in a FASTA file (to speak more generically, I am counting all the letters in a string, excluding lines that begin with ">")

Code:
#Specify the FASTA file to use.
#Version 7: Altered indentation of second for loop.
fasta = open("./fakefasta.faa")
counts = {}
for line in fasta:
    if line[0] == ">":
        continue
    for aa in line:
        if aa not in counts:
            counts[aa] = 1
        else:
            counts[aa] += 1
print(counts)
As you can see by the comment in line 2, I save a new version of the script every time I make an alteration. I don't know proper version conventions (yet) but it serves my purposes for now.

I fucked up because it is counting "\n" as an aa so an rstrip() is missing somewhere. Here's the output.

Code:
{'M': 5, '\n': 7, 'I': 10, 'W': 2, 'G': 15, 'P': 9, 'S': 8, 'L': 50}
EDIT: Here's the final version that makes the letters and each occurrence thereof in column format--
Code:
#Specify the FASTA file to use.
#Version 11.03: Altered value in last print statement to become a str.
fasta = open("./fakefasta.faa")
counts = {}
for line in fasta:
    if line[0] == ">":
        continue
    for aa in line.rstrip("\n"):
        if aa not in counts:
            counts[aa] = 1
        else:
            counts[aa] += 1
for key, value in counts.items():
    print(key +": " + str(value))
And the output:
Code:
M: 5
I: 10
W: 2
G: 15
P: 9
S: 8
L: 50
Now, to evaluate this script I used an input file where the ">" line is a descriptive sentence followed by the exact sequence. That is, the first sequence in the FASTA is called "five methionines" and immediately below it is 5x M's.
 
Last edited:
  • Like
Reactions: Ratko_Falco

Gangster Talk

You lookin' at my gut?
kiwifarms.net
What is the general courtesy in the professional world for git commits? For personal projects I usually use a shitload of commits basically like you would save in a video game and push commits for one line code changes because I do want to try to keep records of what I'm actually doing, I'm on my first professional job and asked the lead developer about this and offered to squash commits but he seemed to not care, though I put in a merge request for like a 50 commit branch and I think he's a bit cranky about it.
 

Least Concern

Pretend I have a waifu avatar like everyone else
kiwifarms.net
Now, to evaluate this script I used an input file where the ">" line is a descriptive sentence followed by the exact sequence. That is, the first sequence in the FASTA is called "five methionines" and immediately below it is 5x M's.
Without seeing your input, it looks like your code is working. Again, did you have a question? If so, please be specific.

As for versioning, if you hope to do this professionally some day, you're going to want to learn git sooner rather than later. git is a pain in the ass to use, but you're going to have a very hard time finding someone to hire you if you don't know it nowadays. It's okay to use a GUI for it as the shell commands can be non-obvious and the man pages might as well be written in Aramaic, but you still need to learn the concepts behind what it's doing behind the scenes. Learn staging, branching and merging, stashing, reverting, and, the best part, bisecting. Rip off that Band-Aid before your bad habits of not using it get too solidified. Speaking of git…

What is the general courtesy in the professional world for git commits? For personal projects I usually use a shitload of commits basically like you would save in a video game and push commits for one line code changes because I do want to try to keep records of what I'm actually doing, I'm on my first professional job and asked the lead developer about this and offered to squash commits but he seemed to not care, though I put in a merge request for like a 50 commit branch and I think he's a bit cranky about it.
Incoming wall of text. Please bear with me; it'll be worth it.

Commits should be atomic. What that means is that each commit should improve one specific thing by itself (so no "mega-commits" that implement several improvements or bug fixes in one commit), and that your code base should still be functional after the commit - no "save my place" commits with half-implemented and untested code which might actually break the project. If you're actually committing after every line change, you won't be at risk of the former, but you definitely need to be careful of the latter.

One major reason for this is the "git bisect" feature, which, as I mentioned above, I definitely recommend people familiarize themselves with. Here's how it works. Let's say you've just noticed that there's a bug in your project, but you're not sure when or how it got there. But you do notice that if you check out your project to a commit from two weeks ago, the bug isn't there. So you know the bug was introduced into the code base some time in the last two weeks. What you do is you type git bisect start, then check out that commit form two weeks ago and do git bisect good, then you check out HEAD and do git bisect bad. Now git will automatically check out a commit right in the middle between the good and bad commits. You test the code and see if the bug is there at that commit, and run git bisect good or git bisect bad accordingly. Depending on your answer, git will again choose a commit halfway between the latest bad and the earliest good commit, so you test again, and so on, until you and git eventually narrow down exactly which commit introduced the bug. From there you can look at the diff for that commit and shame the person that committed it and (or, if it was you, quickly fix it before anybody else notices).

And this works great… so long as you're doing atomic commits as described above. But if the commit that introduced the bug is a "mega-commit," then you've got a massive diff that you have to look through to find exactly which part of the diff introduced the bug. That is, it's easier to find a where a bug got introduced in a 20-line diff than a 200-line one. On the other hand, if one of the commits that git asks you to test was one of those partial "save my place" commits, then maybe you'll go to test it, but you can't tell if the bug in there at that commit because the project won't build or run at all! What do you do in that case? (Well, git bisect skip, but you'll end up with worthless or inconclusive results if you end up having to do that often while bisecting.)

That being said, are you and the lead dev using a pull request model? If so, he's probably not looking at each individual commit anyway, but rather just the diff between the main branch and your branch, and that's going to look the same no matter one commit or 100. So that might be why he doesn't care about your commit style personally. That said, I strongly recommend you get in the habit of doing atomic commits.
 

Daddy Dongle Dinkle

I can't twerk right now, but I'm trying!
kiwifarms.net
I mostly use C++ for many projects, but I have a thing for writing programs in dead programming languages such as Cobal, and Fortran.
 

Gangster Talk

You lookin' at my gut?
kiwifarms.net
Thanks for the informative response, I still like to commit bullshit like "Halfway done (untested)" at the end of the day but it sounds like it's a good idea to at least squash those before I push them.
We are doing pull requests, he mentioned that it's harder to comment on code when there's a bunch of commits but I don't really get how so I wonder if he has some other bug up his ass or if I'm just being self conscious

I mostly use C++ for many projects, but I have a thing for writing programs in dead programming languages such as Cobal, and Fortran.
People often say there's a huge market for coders who can write in legacy languages like COBOL, how long is that going to be the case? I understand it's a herculean task but I would figure all the banks and government departments that run on that stuff would want to update to something newer eventually.
 

Daddy Dongle Dinkle

I can't twerk right now, but I'm trying!
kiwifarms.net
Thanks for the informative response, I still like to commit bullshit like "Halfway done (untested)" at the end of the day but it sounds like it's a good idea to at least squash those before I push them.
We are doing pull requests, he mentioned that it's harder to comment on code when there's a bunch of commits but I don't really get how so I wonder if he has some other bug up his ass or if I'm just being self conscious


People often say there's a huge market for coders who can write in legacy languages like COBOL, how long is that going to be the case? I understand it's a herculean task but I would figure all the banks and government departments that run on that stuff would want to update to something newer eventually.
I just like messing around with old useless shit. But doesn't the government have a track record for being out of touch and inefficient?
 

Least Concern

Pretend I have a waifu avatar like everyone else
kiwifarms.net
People often say there's a huge market for coders who can write in legacy languages like COBOL, how long is that going to be the case? I understand it's a herculean task but I would figure all the banks and government departments that run on that stuff would want to update to something newer eventually.
Jack was a COBOL programmer in the mid to late 1990s. After years of being taken for granted and treated as a technological dinosaur by all the Client/Server programmers and website developers, he was finally getting some respect. He’d become a private consultant specializing in Year 2000 conversions.

Several years of this relentless, mind-numbing work had taken its toll on Jack. He began having anxiety dreams about the Year 2000. All he could think about was how he could avoid the year 2000 and all that came with it.

Jack decided to contact a company that specialized in cryogenics. He made a deal to have himself frozen until March 15th, 2000. The next thing he would know is he’d wake up in the year 2000; after the New Year celebrations and computer debacles; after the leap day. Nothing else to worry about except getting on with his life.

He was put into his cryogenic receptacle, the technicians set the revive date, he was given injections to slow his heartbeat to a bare minimum, and that was that.

The next thing that Jack saw was an enormous and very modern room filled with excited people. They were all shouting “I can’t believe it!” and “It’s a miracle” and “He’s alive!”. There were cameras (unlike any he’d ever seen) and equipment that looked like it came out of a science fiction movie.

Someone who was obviously a spokesperson for the group stepped forward. Jack couldn’t contain his enthusiasm. “Is it over?” he asked. “Is the year 2000 already here? Are all the millennial parties and promotions and crises all over and done with?”

The spokesman explained that there had been a problem with the programming of the timer on Jack’s cryogenic receptacle, it hadn’t been year 2000 compliant. It was actually eight thousand years later, not the year 2000. Technology had advanced to such a degree that everyone had virtual reality interfaces which allowed them to contact anyone else on the planet.

“That sounds terrific,” said Jack. “But I’m curious. Why is everybody so interested in me?”

“Well,” said the spokesman. “The year 10000 is just around the corner, and it says in your files that you know COBOL”.
 

Smaug's Smokey Hole

dragron: the bruges tea soirée
kiwifarms.net
I just like messing around with old useless shit. But doesn't the government have a track record for being out of touch and inefficient?
It's perilous to change something old that works into something that is new and supposed to work in the same way. Everyone that has worked for local government knows that when they say "we're going to upgrade the aging payroll system in six months" it means that it's time to put some extra money aside because that shit never works. For banks, postal services and other important things on a national level the consequences of things being fucked for two-three months is much more severe, so they are essentially running the emperor of mankind on an emulator that is on life support through a beefy cluster of servers built on hardware that doesn't really exist anymore, because if that shit goes down everything goes down.
How do you even safely replace that? It is safer to just add a layer to the sarcophagus by writing another layer of emulation for more modern hardware.
 

Meat Poultry Veg

The staff of life
kiwifarms.net
Here's a simple Python script I wrote that detects what each part of a string is.

Code:
#!/usr/bin/python3

vowels = ["a", "e", "i", "o", "u"]
punct = ["!", "'", '"', ".", ",", "?", ";", "-", ":"]
number = [n for n in range(0,9)]
word = input("Please enter a string. \n")
for i in word:
     if i.lower() in vowels:
          print(i + " is a vowel.")
     elif i == " ":
          continue
     elif i in punct:
          print(i + " is a punctuation mark.")
     elif i in str(number):
          print(i + " is a number.")
     else:
          print(i + " is a consonant.")
And the output:

Code:
Please enter a string. 
A 3-balled tomcat.
A is a vowel.
3 is a number.
- is a punctuation mark.
b is a consonant.
a is a vowel.
l is a consonant.
l is a consonant.
e is a vowel.
d is a consonant.
t is a consonant.
o is a vowel.
m is a consonant.
c is a consonant.
a is a vowel.
t is a consonant.
. is a punctuation mark.
 

Stock Image Photographer

Commander of the Canadian Nazi KKK League
kiwifarms.net
Something that I thought of recently that maybe I'm too much of a brainlet to understand: What's the purpose of embedded scripting languages? Take Lua, for example: You can embed a Lua interpreter in your C program so that it can run Lua code, but then what? What would be the purpose of doing that? I know that game developers do it so they can change some things dynamically without having to bring the whole program down (UI changes for WoW, as an example), but is that the only use for it?

Also, in programming news, Rust should finally be shipping out a new version of the language with async/await syntax built in today. This is one of those issues that has been so important that the devs set up a separate site just to catalog whether or not it has been implemented. Other Rust features of a similar level of importance include GUI libraries and various web functionalities.

EDIT: In personal programming news, I wrote a short python script designed to see what percentage of a certain lolcow's mastodon posts have to do with disgusting bodily functions. Turns out it's right around 10%.
 
Last edited:
Tags
None

About Us

The Kiwi Farms is about eccentric individuals and communities on the Internet. We call them lolcows because they can be milked for amusement or laughs. Our community is bizarrely diverse and spectators are encouraged to join the discussion.

We do not place intrusive ads, host malware, sell data, or run crypto miners with your browser. If you experience these things, you have a virus. If your malware system says otherwise, it is faulty.

Supporting the Forum

How to Help

The Kiwi Farms is constantly attacked by insane people and very expensive to run. It would not be here without community support.

BTC: 1DgS5RfHw7xA82Yxa5BtgZL65ngwSk6bmm
ETH: 0xc1071c60Ae27C8CC3c834E11289205f8F9C78CA5
BAT: 0xc1071c60Ae27C8CC3c834E11289205f8F9C78CA5
LTC: LSZsFCLUreXAZ9oyc9JRUiRwbhkLCsFi4q
XMR: 438fUMciiahbYemDyww6afT1atgqK3tSTX25SEmYknpmenTR6wvXDMeco1ThX2E8gBQgm9eKd1KAtEQvKzNMFrmjJJpiino