Skip to content

create universal reader and writer #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 25, 2020
Merged

create universal reader and writer #209

merged 9 commits into from
Nov 25, 2020

Conversation

ChristinaXu2017
Copy link
Contributor

@ChristinaXu2017 ChristinaXu2017 commented Nov 4, 2020

Description

Our current qio project contains more than 20 different file readers and writers, most of them are similar. Some of them are hardly maintained due to old or deprecated file format. Here a universal file reader and writer is created, which can cover most file format, and also can be used as a base class for special and the complicated file format, such as VCF, FASTA, GFF, Illumina, etc.

Fixes #196 #197 #198

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

A unit test class is added. At moment these three class is not yet used in any projects, it will be further tested after replace current old other reader and writer

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
our internal file read and writer
protected T next;

protected List<String> headerLines = new ArrayList<>();
public RecordReader(final File file) throws IOException { this(file, DEFAULT_BUFFER_SIZE); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

/**
* Here, BufferedReader.close() calls InputStreamReader.close(), which API told us that it Closes the stream and releases any system resources associated with it.
*/
public void close() throws IOException { bin.close(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

* This reader can maxmum take Integer.max lines of file header. Please make other header if bigger than this.
* @return a list of header lines
*/
public List<String> getHeader() { return headerLines; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this pass checkstyle's checks?

if(headerPrefix == null) return nextLine;

//reader header, hence file pointer to first line after header
while ( headerPrefix != null && null != nextLine && nextLine.startsWith(headerPrefix+"") ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null guards have already been performed

try {
next = nextLine == null? null : getRecord(nextLine);
}catch(Exception e) {
throw new IOException("error during retrive first record " + e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling

}

//some record cross multi lines, eg id\nseq\n, this method may call bin.readLine() inside
public abstract T getRecord(String line) throws Exception;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a more specific Exception by thrown here?

* @return the first line just after header
* @throws IOException
*/
public String readHeader(CharSequence headerPrefix ) throws IOException{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change to more meaningful name ie. readHeaderAndReturnFirstNonHeaderLine

}

return rec;
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should avoid catching Exception - be more specific

* This reader can maxmum take Integer.max lines of file header. Please make other header if bigger than this.
* @return a list of header lines
*/
public List<String> getHeader() { return headerLines; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this pass checkstyle's checks?

Copy link
Contributor

@holmeso holmeso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ChristinaXu2017 ChristinaXu2017 merged commit 39f0e8a into master Nov 25, 2020
@ChristinaXu2017 ChristinaXu2017 deleted the Adevelop.qio branch November 30, 2020 09:56
This was referenced Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

passing outer stream into closable FileReader constructor
2 participants