Assignment #0 - Using the command line and parsing input
Download
Late Policy
- The late penalty for assignments is 1% per hour late up to a maximum of 48 hours.
- The points are deducted in integer amounts and rounded down (i.e. 59 minutes late is a 0% penalty).
- You are allowed 1 "free" late submission (up to 48 hours) over the course of all assignments.
- When you apply your "free" late pass, you will not lose any additional points for late turn in of that assignment.
- You must specify that you are using your "free" late pass when you submit your assignment (e-mail both the TA and me).
- Your use of the "free" late is a one-time, irrevocable decision (you can't switch which project you apply it to).
Due: Tues September 12, 2023
Posted: August 31, 2023
Last updated: August 29, 2023
Note: A “skeleton” structure for the project (using Java as the underlying language) has been created here. It shows how to setup the relevant files, and how e.g. one would use build.sh to invoke javac to compile the source into a .class file and how one would create a script named fasta_stats to run the class file.
You will implement a program for parsing a FASTA format file, computing some basic statistics about the records it contains, and printing these statistics to stdout in JSON format.
As you develop your proejct, I highly, highly recommend that you use git for developing your code. If you use a service such as GitHub for hosting your code,
you should develop your code in a private repository.
This program must be written in a compiled, statically-typed language (e.g. not Python). However, there is substantially flexibility in which particular language you want to use. The Gradescope image is outfitted with compilers for C, C++, Go, Java and Rust. We will also consider reasonable requests to add other compiled languages.
Overview
This assignemnt has one component:
A program that parses valid (possibly multi-line) FASTA files, computes certain simple statistics, and writes them to a JSON format output.
Overall structure
You will submit your assignment as a tarball named CMSC423_F23_A0.tar.gz. When this tarball is expanded, it should create a folder named CMSC423_F23_A0. The details of how you structure your “source tree” are up to you, but the following must hold (to enable proper automated testing of your programs).
-
There should be a script at the top-level of
CMSC423_F23_A0calledbuild.sh. This should do whatever is necessary to create a single executables at the top level calledfasta_stats. If you’re comfortable with Makefiles, this can just callmake, or it could simply run the commands necessary to compile your programs and copy them to the top-level directory. You can assume this script is run in abashshell. The generatedfasta_statsfile must be an executable file that can be invoked directly as./fasta_stats input_file. This means that if you are using a language likejava, that requries launching a program with a runtime, thenfasta_statswill likely be a wrapper script that properly invokes the corresponding main java entry point. For a language likeC,C++,Rust, orGo, thenfasta_statswould simply be the compiled binary. -
There should be a
README.mdfile in the top level directory. This README file should contain the following information.- What language have you written your solution in?
- What resources did you consult in working on this assignment (view this as a form of citation; you shouldn’t copy code directly from anywhere in your assignment, but if you consulted other sources please list them here).
Turnin : The assignment turnin will be handled using Gradescope.
The FASTA stats program
You will write a program that reads and parses a FASTA format file and generates statistics about the records in the file. Your program will take a single command line parameter (the path to the input file). The output will be written to stdout. This also means that you should not write any other messages to stdout — if you need to write diagnostic messgages from your program, you should write them to stderr. Your program should be called fasta_stats.
Input
The input consists of 1 argument:
input_file- the path to aFASTAformat file containing the genome records that you should parse.
Each records in the FASTA format consists of 2 parts, a header line (which starts with the > character, followed by a record identifier). The first string after > in each record header will provide a unique identifier for this record. After this record identifier, there may be zero or more other strings providing extra information. You need not worry about them for the purpose of this project. After the header comes the sequence of the record. The sequence consists of a sequence of one or more lines. Each line consists of a sequence of characters (in this case they will all be A, C, G or T). The sequence for a record may span more than one line, in which case the total sequence associated with this record is the concatenation of all sequence lines, removing any occurrences of the \n character. There is no a priori limit on the length of lines, or the length of the sequence string they encode. This means that your parser should implement the appropriate logic when reading a record (i.e. scanning and concatenating the sequence for a record until it encounters the end of the file or the next header). The FASTA file itself, then, just consists of a sequence of such records.
Output
Statistics
Your program should write to stdout a JSON format object (string) with the following information (using the following keys, each associated with the proper value):
min_len- The length of the shortest sequence observed for any record (this is the total sequence length, which may comprise multiple input lines if this is a multi-line record).max_len- The length of the longest sequence observed for any record (this is the total sequence length, which may comprise multiple input lines if this is a multi-line record).mean_len- The average length of sequences observed for the records in the input file.tot_len- The total length of sequences observed for the records in the input file.num_records- The total number of input records observed in the input file.count_a- The total number of occurrences of the nucleotideAappearing in this file.count_c- The total number of occurrences of the nucleotideCappearing in this file.count_g- The total number of occurrences of the nucleotideGappearing in this file.count_t- The total number of occurrences of the nucleotideTappearing in this file.
This information should be written as a properly-formatted JSON object to stdout.
