-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
91 additions
and
85 deletions.
There are no files selected for viewing
77 changes: 0 additions & 77 deletions
77
src/main/java/org/cbioportal/file/export/KeyValueConfigurationWriter.java
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
src/main/java/org/cbioportal/file/export/KeyValueMetadataWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.cbioportal.file.export; | ||
|
||
import org.cbioportal.file.model.CancerStudyMetadata; | ||
import org.cbioportal.file.model.GenericDatatypeMetadata; | ||
import org.cbioportal.file.model.GenericProfileDatatypeMetadata; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.util.LinkedHashMap; | ||
|
||
/** | ||
* A serializer for file model records that serializes them the cBioPortal key-value metadata format. | ||
* e.g. meta_study.txt | ||
*/ | ||
public class KeyValueMetadataWriter { | ||
private final Writer writer; | ||
|
||
/** | ||
* @param writer - the writer to write the key-value metadata to | ||
* e.g. StringWriter, FileWriter | ||
*/ | ||
public KeyValueMetadataWriter(Writer writer) { | ||
this.writer = writer; | ||
} | ||
|
||
/** | ||
* Write a cancer study metadata to the writer | ||
*/ | ||
public void write(CancerStudyMetadata cancerStudyMetadata) { | ||
LinkedHashMap<String, String> metdata = new LinkedHashMap<>(); | ||
metdata.put("type_of_cancer", cancerStudyMetadata.typeOfCancer()); | ||
metdata.put("cancer_study_identifier", cancerStudyMetadata.cancerStudyIdentifier()); | ||
metdata.put("name", cancerStudyMetadata.name()); | ||
metdata.put("description", cancerStudyMetadata.description()); | ||
cancerStudyMetadata.citation().ifPresent(citation -> metdata.put("citation", citation)); | ||
cancerStudyMetadata.pmid().ifPresent(pmid -> metdata.put("pmid", pmid)); | ||
cancerStudyMetadata.groups().ifPresent(groups -> metdata.put("groups", groups)); | ||
cancerStudyMetadata.addGlobalCaseList().ifPresent(addGlobalCaseList -> metdata.put("add_global_case_list", addGlobalCaseList.toString())); | ||
cancerStudyMetadata.tagsFile().ifPresent(tagsFile -> metdata.put("tags_file", tagsFile)); | ||
cancerStudyMetadata.referenceGenome().ifPresent(referenceGenome -> metdata.put("reference_genome", referenceGenome)); | ||
write(metdata); | ||
} | ||
|
||
/** | ||
* Write a generic datatype metadata to the writer | ||
*/ | ||
public void write(GenericDatatypeMetadata genericDatatypeMetadata) { | ||
LinkedHashMap<String, String> metadata = new LinkedHashMap<>(); | ||
metadata.put("cancer_study_identifier", genericDatatypeMetadata.cancerStudyIdentifier()); | ||
metadata.put("generic_alteration_type", genericDatatypeMetadata.geneticAlterationType()); | ||
metadata.put("datatype", genericDatatypeMetadata.datatype()); | ||
metadata.put("data_filename", genericDatatypeMetadata.dataFilename()); | ||
write(metadata); | ||
} | ||
|
||
/** | ||
* Write a generic profile datatype metadata to the writer | ||
*/ | ||
public void write(GenericProfileDatatypeMetadata genericProfileDatatypeMetadata) { | ||
write((GenericDatatypeMetadata) genericProfileDatatypeMetadata); | ||
LinkedHashMap<String, String> metadata = new LinkedHashMap<>(); | ||
metadata.put("stable_id", genericProfileDatatypeMetadata.stableId()); | ||
metadata.put("show_profile_in_analysis_tab", genericProfileDatatypeMetadata.showProfileInAnalysisTab().toString().toLowerCase()); | ||
metadata.put("profile_name", genericProfileDatatypeMetadata.profileName()); | ||
metadata.put("profile_description", genericProfileDatatypeMetadata.profileDescription()); | ||
genericProfileDatatypeMetadata.genePanel().ifPresent(genePanel -> metadata.put("gene_panel", genePanel)); | ||
write(metadata); | ||
} | ||
|
||
private void write(LinkedHashMap<String, String> metadata) { | ||
metadata.forEach((key, value) -> { | ||
try { | ||
writer.write(composeKeyValueLine(key, value)); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}); | ||
} | ||
|
||
private static String composeKeyValueLine(String key, String value) { | ||
return key + ": " + value + "\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...le/model/GenericDatatypeFileMetadata.java → ...l/file/model/GenericDatatypeMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g/cbioportal/file/model/StudyRelated.java → ...rtal/file/model/StudyRelatedMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package org.cbioportal.file.model; | ||
|
||
public interface StudyRelated { | ||
public interface StudyRelatedMetadata { | ||
String cancerStudyIdentifier(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters