Skip to content

Commit

Permalink
review comments - removing unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-ebi committed Feb 12, 2024
1 parent cb4f0f4 commit 530f623
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 377 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Repository;
import uk.ac.ebi.eva.contigalias.dus.ENAAssemblyReportReader;
import uk.ac.ebi.eva.contigalias.dus.ENAAssemblyReportReaderFactory;
import uk.ac.ebi.eva.contigalias.dus.ENABrowser;
import uk.ac.ebi.eva.contigalias.dus.ENABrowserFactory;
import uk.ac.ebi.eva.contigalias.entities.ChromosomeEntity;
Expand All @@ -34,7 +33,6 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand All @@ -45,16 +43,12 @@ public class ENAAssemblyDataSource {

private final ENABrowserFactory factory;

private final ENAAssemblyReportReaderFactory readerFactory;

@Value("${asm.file.download.dir}")
private String asmFileDownloadDir;

@Autowired
public ENAAssemblyDataSource(ENABrowserFactory factory,
ENAAssemblyReportReaderFactory readerFactory) {
public ENAAssemblyDataSource(ENABrowserFactory factory) {
this.factory = factory;
this.readerFactory = readerFactory;
}

public Optional<Path> downloadAssemblyReport(String accession) throws IOException {
Expand Down Expand Up @@ -97,14 +91,7 @@ public Optional<Path> downloadAssemblyReport(ENABrowser enaBrowser, String acces
}

public List<ChromosomeEntity> getChromosomeEntityList(List<String> chrDataList) {
List<ChromosomeEntity> chromosomeEntityList = new ArrayList<>();
for (String chrData : chrDataList) {
ChromosomeEntity chromosomeEntity = getChromosomeEntity(chrData);
if (chromosomeEntity != null) {
chromosomeEntityList.add(chromosomeEntity);
}
}
return chromosomeEntityList;
return ENAAssemblyReportReader.getChromosomeEntity(chrDataList);
}

public ChromosomeEntity getChromosomeEntity(String chrLine) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Repository;
import uk.ac.ebi.eva.contigalias.dus.NCBIAssemblyReportReader;
import uk.ac.ebi.eva.contigalias.dus.NCBIAssemblyReportReaderFactory;
import uk.ac.ebi.eva.contigalias.dus.NCBIBrowser;
import uk.ac.ebi.eva.contigalias.dus.NCBIBrowserFactory;
import uk.ac.ebi.eva.contigalias.entities.AssemblyEntity;
Expand All @@ -35,7 +34,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand All @@ -47,16 +45,12 @@ public class NCBIAssemblyDataSource {

private final NCBIBrowserFactory factory;

private final NCBIAssemblyReportReaderFactory readerFactory;

@Value("${asm.file.download.dir}")
private String asmFileDownloadDir;

@Autowired
public NCBIAssemblyDataSource(NCBIBrowserFactory factory,
NCBIAssemblyReportReaderFactory readerFactory) {
public NCBIAssemblyDataSource(NCBIBrowserFactory factory) {
this.factory = factory;
this.readerFactory = readerFactory;
}

public AssemblyEntity getAssemblyEntity(Path downloadFilePath) throws IOException {
Expand All @@ -71,13 +65,8 @@ public AssemblyEntity getAssemblyEntity(List<String> asmDataLines) {
}

public List<ChromosomeEntity> getChromosomeEntityList(AssemblyEntity assemblyEntity, List<String> chrDataList) {
List<ChromosomeEntity> chromosomeEntityList = new ArrayList<>();
for (String chrData : chrDataList) {
ChromosomeEntity chromosomeEntity = getChromosomeEntity(assemblyEntity, chrData);
if (chromosomeEntity != null) {
chromosomeEntityList.add(chromosomeEntity);
}
}
List<ChromosomeEntity> chromosomeEntityList = NCBIAssemblyReportReader.getChromosomeEntity(chrDataList);
chromosomeEntityList.stream().forEach(c -> c.setAssembly(assemblyEntity));
return chromosomeEntityList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,90 +16,24 @@

package uk.ac.ebi.eva.contigalias.dus;

import uk.ac.ebi.eva.contigalias.entities.AssemblyEntity;
import uk.ac.ebi.eva.contigalias.entities.ChromosomeEntity;
import uk.ac.ebi.eva.contigalias.entities.SequenceEntity;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;

public class ENAAssemblyReportReader extends AssemblyReportReader {
public class ENAAssemblyReportReader {

public ENAAssemblyReportReader(InputStreamReader inputStreamReader, boolean isScaffoldsEnabled) {
super(inputStreamReader, isScaffoldsEnabled);
}

protected void parseReport() throws IOException, NullPointerException {
if (reader == null) {
throw new NullPointerException("Cannot use AssemblyReportReader without having a valid InputStreamReader.");
}
String line = reader.readLine();
while (line != null) {
if (line.startsWith("accession")) {
if (assemblyEntity == null) {
assemblyEntity = new AssemblyEntity();
}
parseAssemblyData(line);
} else if (!line.startsWith("accession")) {
String[] columns = line.split("\t", -1);
if (columns.length >= 6) {
if (columns[5].equals("Chromosome") && columns[3].equals("assembled-molecule")) {
parseChromosomeLine(columns);
} else if (isScaffoldsEnabled) {
parseScaffoldLine(columns);
}
}
public static List<ChromosomeEntity> getChromosomeEntity(List<String> lines) {
List<ChromosomeEntity> chromosomeEntityList = new ArrayList<>();
for (String line : lines) {
ChromosomeEntity chromosomeEntity = getChromosomeEntity(line);
if (chromosomeEntity != null) {
chromosomeEntityList.add(chromosomeEntity);
}
line = reader.readLine();
}
reportParsed = true;
reader.close();
}

// Not present in ENA assembly reports
protected void parseAssemblyData(String line) {
}

protected void parseChromosomeLine(String[] columns) {
ChromosomeEntity chromosomeEntity = getChromosome(columns);
if (chromosomeEntity == null) {
return;
}

if (assemblyEntity == null) {
assemblyEntity = new AssemblyEntity();
}
chromosomeEntity.setAssembly(this.assemblyEntity);
chromosomeEntity.setContigType(SequenceEntity.ContigType.CHROMOSOME);

List<ChromosomeEntity> chromosomes = this.assemblyEntity.getChromosomes();
if (chromosomes == null) {
chromosomes = new LinkedList<>();
assemblyEntity.setChromosomes(chromosomes);
}
chromosomes.add(chromosomeEntity);
}

protected void parseScaffoldLine(String[] columns) {
ChromosomeEntity scaffoldEntity = getScaffold(columns);
if (scaffoldEntity == null) {
return;
}

if (assemblyEntity == null) {
assemblyEntity = new AssemblyEntity();
}
scaffoldEntity.setAssembly(this.assemblyEntity);
scaffoldEntity.setContigType(SequenceEntity.ContigType.SCAFFOLD);

List<ChromosomeEntity> scaffolds = this.assemblyEntity.getChromosomes();
if (scaffolds == null) {
scaffolds = new LinkedList<>();
assemblyEntity.setChromosomes(scaffolds);
}
scaffolds.add(scaffoldEntity);
return chromosomeEntityList;
}

public static ChromosomeEntity getChromosomeEntity(String line) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,119 +20,12 @@
import uk.ac.ebi.eva.contigalias.entities.ChromosomeEntity;
import uk.ac.ebi.eva.contigalias.entities.SequenceEntity;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class NCBIAssemblyReportReader extends AssemblyReportReader {

public NCBIAssemblyReportReader(InputStreamReader inputStreamReader, boolean isScaffoldsEnabled) {
super(inputStreamReader, isScaffoldsEnabled);
}

protected void parseReport() throws IOException, NullPointerException {
if (reader == null) {
throw new NullPointerException("Cannot use AssemblyReportReader without having a valid InputStreamReader.");
}
String line = reader.readLine();
while (line != null) {
if (line.startsWith("# ")) {
if (assemblyEntity == null) {
assemblyEntity = new AssemblyEntity();
}
parseAssemblyData(line);
} else if (!line.startsWith("#")) {
String[] columns = line.split("\t", -1);
if (columns.length >= 6 && (columns[5].equals("=") || columns[5].equals("<>")) &&
(columns[4] != null && !columns[4].isEmpty() && !columns[4].equals("na"))) {
if (columns[3].equals("Chromosome") && columns[1].equals("assembled-molecule")) {
parseChromosomeLine(columns);
} else if (isScaffoldsEnabled) {
parseScaffoldLine(columns);
}
}
}
line = reader.readLine();
}
reportParsed = true;
reader.close();
}

protected void parseAssemblyData(String line) {
int tagEnd = line.indexOf(':');
if (tagEnd == -1) {
return;
}
String tag = line.substring(2, tagEnd);
String tagData = line.substring(tagEnd + 1).trim();
switch (tag) {
case "Assembly name": {
assemblyEntity.setName(tagData);
break;
}
case "Organism name": {
assemblyEntity.setOrganism(tagData);
break;
}
case "Taxid": {
assemblyEntity.setTaxid(Long.parseLong(tagData));
break;
}
case "GenBank assembly accession": {
assemblyEntity.setInsdcAccession(tagData);
break;
}
case "RefSeq assembly accession": {
assemblyEntity.setRefseq(tagData);
break;
}
case "RefSeq assembly and GenBank assemblies identical": {
assemblyEntity.setGenbankRefseqIdentical(tagData.equals("yes"));
break;
}
}
}

protected void parseChromosomeLine(String[] columns) {
ChromosomeEntity chromosomeEntity = getChromosome(columns);
if (chromosomeEntity == null) {
return;
}

if (assemblyEntity == null) {
assemblyEntity = new AssemblyEntity();
}
chromosomeEntity.setAssembly(this.assemblyEntity);

List<ChromosomeEntity> chromosomes = this.assemblyEntity.getChromosomes();
if (chromosomes == null) {
chromosomes = new LinkedList<>();
assemblyEntity.setChromosomes(chromosomes);
}
chromosomes.add(chromosomeEntity);
}

protected void parseScaffoldLine(String[] columns) {
ChromosomeEntity scaffoldEntity = getScaffold(columns);
if (scaffoldEntity == null) {
return;
}

if (assemblyEntity == null) {
assemblyEntity = new AssemblyEntity();
}
scaffoldEntity.setAssembly(this.assemblyEntity);

List<ChromosomeEntity> scaffolds = this.assemblyEntity.getChromosomes();
if (scaffolds == null) {
scaffolds = new LinkedList<>();
assemblyEntity.setChromosomes(scaffolds);
}
scaffolds.add(scaffoldEntity);
}
public class NCBIAssemblyReportReader {

public static AssemblyEntity getAssemblyEntity(List<String> lines) {
Map<String, String> tagAndValuesMap = lines.stream()
Expand Down Expand Up @@ -175,6 +68,17 @@ public static AssemblyEntity getAssemblyEntity(List<String> lines) {
return asmEntity;
}

public static List<ChromosomeEntity> getChromosomeEntity(List<String> lines) {
List<ChromosomeEntity> chromosomeEntityList = new ArrayList<>();
for (String line : lines) {
ChromosomeEntity chromosomeEntity = getChromosomeEntity(line);
if (chromosomeEntity != null) {
chromosomeEntityList.add(chromosomeEntity);
}
}
return chromosomeEntityList;
}

public static ChromosomeEntity getChromosomeEntity(String line) {
String[] columns = line.split("\t", -1);
if (columns.length >= 6 && (columns[5].equals("=") || columns[5].equals("<>")) &&
Expand Down
Loading

0 comments on commit 530f623

Please sign in to comment.